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.

Mon Nov 04, 2019 3:45 pm

hi,

i want to transform my pdf with x pages into x images.
I can do that in a For, but this take too much time. I want to accelerate the process, with a parallel for, but i have some issues with this method.

I can't use the same PdfDocument to save each page in parallel, and if i open the document x times (in each loop), i have sometimes a blank image.
Have you a proper process to do that ?

Regards

[email protected]
 
Posts: 3
Joined: Thu Sep 14, 2017 4:31 am

Tue Nov 05, 2019 3:51 am

Hi,

Thanks for your inquiry.
To help us investigate your issue accurately, please offer us the following information.
1. Your input Pdf file.
2. The complete code you were using which could reproduce your issue directly.
You could upload them here or send us([email protected]) via email.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Tue Nov 05, 2019 8:26 am

Hey,

There is my code :

Using doc As New sp.PdfDocument()
doc.LoadFromFile(pathImg)
nbPages = doc.Pages.Count()
doc.Close()
End Using

Parallel.For(0, nbPages,
Sub(i)
Dim index As Integer = i + CompteurImgConvert

Using pdfTmp As New sp.PdfDocument
Threading.Thread.Sleep(i * 100)
pdfTmp.LoadFromFile(pathImg)

Using emf As Image = pdfTmp.SaveAsImage(i, PdfImageType.Bitmap)
Dim pathTmp As String = Path.Combine(CacheTemporaire, "MediaTmp", nameFile)

emf.Save(pathTmp, ImageFormat.Png)
End Using

pdfTmp.Close()
End Using
End Sub)


The sleep is the only one solution i have found to do work the parallel for without blank pages.
And if possible i would to use the same pdfDocument without reopen it.

the problems occur on all my pdfs, I don't think you need them for an example.

[email protected]
 
Posts: 3
Joined: Thu Sep 14, 2017 4:31 am

Tue Nov 05, 2019 10:40 am

Hi,

Thanks for your information.
I tested your code but encountered other issue. The code "emf.Save(pathTmp, ImageFormat.Png)" threw the System.Runtime.InteropServices.ExternalException exception which showed a general error occurred in GDI +.
Anyway, I have logged this issue into our bug tracking system. Once there is any progress, we will inform you. Sorry for the inconvenience caused.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Wed Nov 13, 2019 10:12 am

Hi,

Hope you are doing well.
After further investigate, we couldn't reproduce your issue on our side. There won't be the blank image during the conversion. I have attached my project here, please check it: http://www.e-iceblue.com/downloads/demo/19438TestThreadVB.zip

If the issue still exists, I'm afraid it is difficult for us to locate the reason of your issue if we don't reproduce it on our side. To help us investigate it accurately, could you please offer us the following information?
1. A runnable project which could reproduce your issue directly.
2. The OS and Region information, e.g. Win7 64bit, China/Chinese.

You could upload them here or send us([email protected]) via email.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Return to Spire.PDF