Error: Cannot open PDF file

If you are a Delphi developer and have any questions about using our products from Delphi here is the place to post them.
Post Reply
jacaley
Posts: 4
Joined: Mon Jun 02 2003

Error: Cannot open PDF file

Post by jacaley » Mon Jun 02 2003

I'm working on a service with produces PDFs for viewing with a web browser. The service uses threads and they are pooled. I'm creating a PDF Printer when the service begins (using PDFDriverInit) and then when each thread needs to create a new PDF I create a new printer object and "attach" to the PDF printer using DriverInit. This seens to work well but when I get multiple browser windows open ( more than 2 ) and try to create several different pdf files - I get an error "Cannot open file XXX.pdf". (where XXX represents the temporary file name created on the fly) If I try to create 3 files, 2 of the three will be OK - the other I'll get the error message that it wasn't able to open the PDF file. If I go slowly there are no problems, it is only when I attempt several files at the same time. Any thoughts as to why this is happening? When the thread creates the new printer object I set the file options (NoPromt + UseFileName) and the SetDefaultFileName all within a critical section.

Any help would be appreciated.

Thanks,
John

Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan » Tue Jun 03 2003

Hello,

I guess what you are facing is multithreading. Different print jobs are trying to access the PDF Printer at the same time.

To overcome this issue you don't need to call DriverInit many times.
Calling PDFDriverInit when launching your application is enought. You will need instead to use the locking mechanism of CDIntf.

This is available starting version 2.06 of the PDF Converter.
For more details on using the locking mechanism please download our Delphi technical note from: http://www.amyuni.com/en/support/technotes.html

Hope this helps 8)

jacaley
Posts: 4
Joined: Mon Jun 02 2003

Cannot open PDF File

Post by jacaley » Tue Jun 03 2003

Joan - thanks for your reply -

I'm only calling PDFDriverInit once - then in each thread I'm creating a new printer object and calling DriverInit (as shown in your Technical Note #01). Are you saying there is something else that needs to be done to lock the object while printing?

Thanks
John

Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan » Wed Jun 04 2003

Hello,

If the issue you are having is due to the fact that you are trying to open the pdf file before it is saved to disk than you will need to wait a little bit until the file is generated to open it.
This can be done by using the Broadcast Messages event of the driver.

If the issue you are facing is to the fact that two or more print jobs are trying to change the printer properties at the same time than you need to use the locking mechanism of CDintf available starting version 2.06 of the driver.

From your application you can know in which situation you are, when you do this please contact our Technical Support support@amyuni.com so they can provide you with samples on either of the above methods.

Hope this helps.

jacaley
Posts: 4
Joined: Mon Jun 02 2003

Multiple Print Jobs

Post by jacaley » Wed Jun 04 2003

Joan - Thanks for the reply -

I figured out how to get it to work in my code. When I create the printer object in a thread I use a critical section to create, set the file options, file name and issue a begindoc before leaving the critical section.

The only problem I still have is that if I've got 5 threads all executing at the same time, they are done sequencially, in the order that they were requested. Which means that if the first thread has a very large print job of several pages all the other print jobs wait until it is finished before processing. I was needing a way for them all to be processed at the same time.

Thanks,
John

Post Reply