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 Sep 09, 2021 11:15 am

We are using Spire.PDF 7.7.10 in our WPF application and are facing the following issue. We are loading a PDF document and try to save it as a high-res image using the SaveAsImage method. Unfortunately, we are facing an System.ArgumentException "Parameter is not valid." at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format). We are observing this kind of exception in particular for PDF documents with layers, as the one attached. To reproduce our issue, simply load the PDF using the "LoadFromStream" method and call "SaveAsImage".

We are looking forward to your reply.

Best regards,

Thomas

troithmeier
 
Posts: 19
Joined: Tue Sep 04, 2018 12:24 pm

Fri Sep 10, 2021 7:30 am

Hi,

Thank you for your inquiry.
I did a test but didn't reproduce your issue on my side. I would suggest that you give the latest version(Spire.PDF Pack(Hot Fix) Version:7.9.2) a try as it contains more fixes than the old versions. If the problem still exists after trying, please provide the following information for further investigation. Thanks in advance.
1) Your test environment, such as OS info (E.g. Windows 7, 64-bit) and region setting (E.g. China, Chinese).
2) Your project target framework (E.g. .NET Framework 4.5).

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Fri Sep 10, 2021 9:01 am

Hi,

Unfortunately, updating to the most recent version 7.9.2 did not resolve our issue. Please find below the requested information required for further investigation:

OS: Microsoft Windows 10 Pro, 64-bit
Region Setting: English, United States
Target Framework: .NET Framework 4.7.1

I hope this information enables you to reproduce the issue.

Regards,

Thomas

troithmeier
 
Posts: 19
Joined: Tue Sep 04, 2018 12:24 pm

Fri Sep 10, 2021 10:42 am

Hi,

Thank you for your sharing.
I tested again in the same environment as yours, but still did not reproduce your problem. Here I attached my test demo for your reference, please have a try on your side. Looking forward to your feedback.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Mon Sep 13, 2021 6:51 am

Hi,

Thank you for sharing the demo project. I've run the demo on our system and I am still encountering the mentioned issue. Interestingly, the exception is not causing the application to crash, and the "SaveAsImage" command even generates the desired output, even though the exception is thrown multiple times during the save process, as shown below:

Screenshot.PNG


In your sample the exception seems to be catched somewhere internally, in our scenario this is not the case. One probable reason might be that we are calling "SaveAsImage" within a "Task.Run(()...)", because otherwise the entire UI thread is being blocked. Could this be the issue?

Best regards,

Thomas

troithmeier
 
Posts: 19
Joined: Tue Sep 04, 2018 12:24 pm

Mon Sep 13, 2021 7:17 am

Amendment: It also appears that the most recent nuget package does not offer the same method interfaces as the libraries used in your sample, e.g. the SaveAsImage method supports a different set of parameters and returns a BitmapSource object in the latter case.

troithmeier
 
Posts: 19
Joined: Tue Sep 04, 2018 12:24 pm

Mon Sep 13, 2021 11:34 am

Hello,

Thank you for your feedback.
Kindly note that our Spire.PDF package includes dll for Net and Wpf. In the sample WPF application I provided, the dll used is for Wpf, and the SaveAsImage method will return the BitmapSource type. If import the dll directly from Nuget manager, it will install the dll of Net, the SaveAsImage method will return the Image type. The strange thing was that I have tested the dlls of Wpf and Net respectively in my sample, but neither of them could reproduce your issue. Did you modify my project while running? If not, I guessed the issue may be related to some settings of your Visual Studio. Please provide your version of Visual Studio for our reference. Besides, I suggest that you try my application on other computers to check if there is any difference.
By the way, you mentioned that your real case is doing with Task.Run(()...), could you please provide your full code of Task.Run(()...) for our reference? It would be helpful if you could share your whole project. You could upload it via OneDrive or DropBox, then share us with the link to download. Thanks in advance.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Tue Sep 14, 2021 11:48 am

Hello,

Simply wrapping the pdfDocument.SaveAsImage call within a "Task.Run(() => {}" triggers an exception stating that this operation requires the STA thread. However, if not invoking the method within a separate task the whole UI freezes for the duration of the save image task. This can also be observed in the sample you provided.

Regards,

Thomas

troithmeier
 
Posts: 19
Joined: Tue Sep 04, 2018 12:24 pm

Wed Sep 15, 2021 10:42 am

Hi,

Thank you for your feedback.
I did an initial test with "Task.Run(() => {}", and found the behavior you mentioned. I have logged the issue into our Bug tracking system with the ticket number SPIREPDF-4648. Our development team will investigate and fix it. Once it is resolved or there is any update, I will inform you. Sorry for the inconvenience caused.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Wed Sep 15, 2021 11:40 am

Hi,

Thank you for efforts and your quick responses! We are looking forward to hearing from you.

Yours sincerely,

Thomas

troithmeier
 
Posts: 19
Joined: Tue Sep 04, 2018 12:24 pm

Return to Spire.PDF