Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu Jan 20, 2022 2:15 am

Hello,

I'm currently using Spire.Office v6.12.1 as a licensed user. I'm trying to create a PdfImage from an existing Pdf Document and draw it onto a new Pdf Document.

This is the code block I'm using in order to accomplish this:

Code: Select all
using (var imageStream = pdfDoc.SaveAsImage(i)) {
      // Create a new page with the same size as the original pdf that the image is created from
      var newPage = newDoc.Pages.Add(pdfDoc.Pages[i].Size);

      var image = PdfImage.FromStream(imageStream);
      float widthFitRate = image.PhysicalDimension.Width / newPage.Canvas.Size.Width;
      float heightFitRate = image.PhysicalDimension.Height / newPage.Canvas.Size.Height;
      float fitRate = Math.Max(widthFitRate, heightFitRate);
      float fitWidth = image.PhysicalDimension.Width / fitRate;
      float fitHeight = image.PhysicalDimension.Height / fitRate;

      newPage.Canvas.DrawImage(image, 0, (newPage.Canvas.ClientSize.Height - image.Height), fitWidth, fitHeight);
}


The resulting image appears to have cropped off the bottom half of the document I am converting. If I switch the nuget package I am using to Spire.Office.NETCore v 6.12.1 and update the code above to this:

Code: Select all
using (var image = pdfDoc.SaveAsImage(i)) {
      // Create a new page with the same size as the original pdf that the image is created from
      var newPage = newDoc.Pages.Add(pdfDoc.Pages[i].Size);

      var pdfImage = PdfImage.FromImage(image);
      float widthFitRate = pdfImage .PhysicalDimension.Width / newPage.Canvas.Size.Width;
      float heightFitRate = pdfImage .PhysicalDimension.Height / newPage.Canvas.Size.Height;
      float fitRate = Math.Max(widthFitRate, heightFitRate);
      float fitWidth = pdfImage .PhysicalDimension.Width / fitRate;
      float fitHeight = pdfImage .PhysicalDimension.Height / fitRate;

      newPage.Canvas.DrawImage(pdfImage , 0, 0, fitWidth, fitHeight);
}


The resulting document has the full image on the page uncropped as expected.

What is going on with the current version of Spire.Office v6.12.1? Is it safe for me to just use the NETCore version of the library instead or is that too far behind with regards to bug fixes?

Please let me know when you can. I've attached the file I've been testing with and getting these results.

OoPdfFormExample.zip


Thank you,
Zac

ZCliff92
 
Posts: 30
Joined: Thu Jan 20, 2022 1:58 am

Thu Jan 20, 2022 9:18 am

Hello,

Thanks for your inquiry!

Kindly note that when the framework of your project is .netcore3.1 and the lower version of .netcore, if you install the Spire.Office 6.12.1 via Nuget directly, the Nuget will reference the dlls for .netstandard in auto; But if install the Spire.Office.NetCore 6.12.1 , the Nuget will reference the dlls for netcore. Since we use SkiaSharp to handle the image in netstandard dlls, but System.Drawing in netcore, the different between these two will lead to the issue you meet

Start with the latest version of Spire.Office for net 7.1.2 we released today, we have some changes in Nuget installing. For the normal Spire.Office package in Nuget, we remove the dlls for netstandard, and keep the dlls for netcore 2 3 5 6, net framework 2,4,4+ .etc. And we add a new package called Spire.Officefor.NETStandard, this pakage only keeps the dlls for netstandard in it. We will keep updating these two pakages in the future. For the package of Spire.Office.NETCore, we will stop updating on it since the Spire.Office package is enough for netcore project.

For your issue, I just recommend that you can install the latest Spire.Office 7.1.2 via Nuget, and use the second part code you provided to generate the correct image. Besides, I also logged the issue of the content of the generated file is move down after converting file to image with the netstandard dlls in our issue tracking system with the ticket SPIREPDF-4916 for further investigation.

We will let you know if there is any update. Sorry for the inconvenience caused.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Tue Feb 01, 2022 4:11 pm

Hi,
I'm getting a error on my kubernetes environment when saving pdf as image. Error is
"System.TypeInitializationException: The type initializer for 'sprᜭ' threw an exception.\n ---> System.InvalidOperationException: Cannot found font installed on the system.\n
at spr╨.ᜀ(String A_0, FontStyle A_1, String A_2)\n at sprᜎ..ctor(String A_0, FontStyle A_1)\n at sprᜌ..ctor(String A_0, Single A_1, FontStyle A_2)\n
at sprᜭ..cctor()\n --- End of inner exception stack trace ---\n at spr⪷.ᜃ()\n at spr⪷.ᜁ(Single A_0)\n at spr⪷.ᜃ(Single A_0)\n
at spr⩗.ᜀ(sprᜏ A_0, spr⩔ A_1, Boolean A_2, Boolean A_3)\n at spr⩗.ᜁ(sprᜏ A_0, spr⩔ A_1, Boolean A_2, Boolean A_3)\n
at spr⩔.ᜀ(String A_0, spr⪷ A_1, String A_2, Boolean A_3)\n at spr⩔.ᜀ(String[] A_0, String A_1)\n at spr⩔.ᜀ(spr⪺ A_0)\n at spr⩔.᜼()\n at spr⩔.ᜍ(Boolean A_0)\n
at spr᪀.ᜀ(sprᜏ A_0, spr⩋ A_1, spr⪹ A_2, spr⪻ A_3, sprᜓ A_4)\n at spr᪀.ᜁ(Int32 A_0, Int32 A_1, Int32 A_2)\n at Spire.Pdf.PdfDocumentBase.ᜀ(Int32 A_0, Int32 A_1, Int32 A_2)\n
at Spire.Pdf.PdfDocumentBase.ᜁ(Int32 A_0)\n at Spire.Pdf.PdfDocument.SaveAsImage(Int32 pageIndex)\n"

This library works fine in local and Azure Linux app service. But it continues to give above error inside Docker.
Environment in .NET core 3.1 and I have used spirePDF 7.8.9 and Dependency Libraries are "SkiaSharp 2.80.3" and" SkiaSharp.NativeAssets.Linux.NoDependencies 2.80.3"

rmdevsam2
 
Posts: 4
Joined: Tue Feb 01, 2022 4:00 pm

Wed Feb 02, 2022 7:46 am

Hello rmdevsam2,

Thanks for your inquiry.
First, please install all fonts used in your pdf file on Docker.
Besides, because you are using an old version of our Spire.PDF, we recommend you upgrade to the latest version and try again.
If the issue persists, please provide you input file for further investigation. Thanks in advance.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Wed Feb 02, 2022 8:45 am

Thank you for the response. I will try the given approach

rmdevsam2
 
Posts: 4
Joined: Tue Feb 01, 2022 4:00 pm

Fri Feb 11, 2022 9:43 am

Hello rmdevsam2,

Greetings from E-iceblue!
Has your issue been resolved? Any feedback will be greatly appreciated.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Fri May 27, 2022 10:32 am

Hi Zac,

Thanks for your patient waiting.
Glad to inform you that the reported issue SPIREPDF-4916 has been resolved and the hotfix (Spire.Office Platinum(Hotfix) Version:7.5.4) is available. Please download it from the following link.
Website download link: https://www.e-iceblue.com/Download/down ... t-now.html
Nuget download link: https://www.nuget.org/packages/Spire.Office/7.5.4

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.PDF

cron