Determining When A PDF Creation Is Finished - Here's How To!

About the programming interface for the virtual PDF printer driver.

Moderator: jr

Determining When A PDF Creation Is Finished - Here's How To!

Postby Mark Bradley » Sat Nov 14, 2009 12:40 am

Well it looks like it took an old dBase Plus programmer like me to solve this vexing problem of programmatically determining simply, exactly, reliably and definitely when Bullzip has finished creating a PDF file. I can understand why Bullzip itself can't really be expected to inform a calling program that it has finished it's work as it is only a server and the traffic is pretty much one-way from client to server.

So are you ready for it? Do you really want me to tell you?? Oh all right then, here is the solution.

The key to it all is simply to measure when the target PDF file has stopped growing. Below is the code I wrote (in dBase Plus) to accomplish this. It is a snippet from a program that prints a PDF file from a Microsoft Word document. When the snippet finishes, some more code then sends the PDF file to Outlook for emailing. Therefore I HAVE to be sure that the PDF file has actually finished being created!

VB programmers will need to "translate" the code into something that VB understands of course. Perhaps one of our more distinguished VB programmers can quickly create a VB version of the code that works and post it back here for all to enjoy?

I have tested this code on PDF files containing from 1 to over 100 pages in length and it works flawlessly every time.

Ok, here goes (watch out for word wrap):

// Ensure Bullzip PDF Writer is installed

Try
oPDF = new oleAutoclient("Bullzip.PDFPrinterSettings")
oPDF.init()
BullZipInstalled = true

// modify Bullzip PDF Printer settings to suit

oPDF.setvalue("Output",xpdf)
oPDF.setvalue("Showpdf",iif(form.PREVIEWCHECKBOX.value,"yes","no"))
oPDF.setvalue("Showprogress","yes")
oPDF.setvalue("ConfirmOverwrite","no")
oPDF.setvalue("ShowSaveAS","never")
oPDF.setvalue("ShowSettings","never")
oPDF.WriteSettings()

Catch (Exception e)
BullZipInstalled = false
Endtry

If BullZipInstalled = True

xpdf = "Path To File\Filename.pdf"
oldPrint = oWord.Documents.Application.ActivePrinter
PrinterName = oPDF.GetPrinterName()
oWord.Documents.Application.ActivePrinter = PrinterName
oWord.ActiveDocument.PrintOut()

// Loop until the PDF file creation is actually finished. This is done by ascertaining when the file has finished growing

Do While True
If file(xpdf) // If the PDF file exists
Check1 = new File().size( xpdf ) // Measure the size of the PDF file
sleep 1 // Wait 1 second
Check2 = new File().size( xpdf ) // Measure the size of the PDF file again to see if it's still growing
If Check1 = Check2 // If the PDF file has finished growing, exit the loop
exit
Endif
Else // If file doesn't exist yet, wait 1 second then loop and try again
sleep 1
Endif
Endd
Endif

oWord.Documents.Application.ActivePrinter = oldPrint
oWord.quit( 0 )

Good luck and I hope it works for you as well as it works for me!

Mark Bradley.
Mark Bradley
 
Posts: 2
Joined: Fri Nov 13, 2009 3:34 pm

Re: Determining When A PDF Creation Is Finished - Here's How To!

Postby jr » Fri Mar 05, 2010 9:51 pm

Hi Mark,

Thank you for the code. It is probably a very good way to solve that problem. I have two alternatives for you.

1) Wait for the target file to exist. Then wait until you are allowed to open it exclusively.

2) Use the statusfile setting.

The statusfile setting can point to a file name that will be created when the conversion process is done. It is also created if an error occurs.

If you start by deleting the existing status file or specify a unique name for each print job then you can just wait for the file to appear.

Regards,
Jacob
jr
Site Admin
 
Posts: 491
Joined: Sun Mar 26, 2006 12:28 pm

Re: Determining When A PDF Creation Is Finished - Here's How To!

Postby Fixfinn » Wed Apr 21, 2010 3:21 pm

Hi!

Where is the Statusfile?
Fixfinn
 
Posts: 4
Joined: Mon Jan 11, 2010 11:19 am

Re: Determining When A PDF Creation Is Finished - Here's How To!

Postby stafferlink » Thu Jul 15, 2010 8:45 pm

I prefer:

Bullzip.PdfWriter.PdfUtil.WaitForFile(strSourcePDF, iTimeout)
stafferlink
 
Posts: 2
Joined: Fri Jul 02, 2010 7:17 pm


Return to Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron