Job stuck in queue. No PDF created. (Win7 and version 1.2.0)

I am using the COM interface in VB code behind an Access 2000 form.  At the end is a code sample.   What happens is 1 time out of 10 the PDF file never gets created.  Instead the job sits in the queue. I did a file monitor trace and see that, during successful printings, at some point after combining the jobs into one a trailing 426 bytes (see below) are written to the final temp file PDFCreator uses just before converting it to a PDF.  However in the failure cases these bytes are not written.  I do not see any error messages by PDFCreator, i.e. the code nevers jumps to errPDFCreator:

I have tried adding delays before and after DoEvents, but no success.  I've disabled anti-virus software just to be sure there was no interference, still the problem exists. I'm a local admin so there should not be any permissions issues.

Windows 7 Professional
PDFCreator 1.0.2 and 1.2.0 both exhibit this behavior.


I have not reproduced the error on Win XP.

It's as if the command .cPrinterStop = False
doesn't work all the time.


Help!


Sub PrintAccessReportToPDF(...)

  On Error GoTo errPDFCreator
    Dim intPageCount As Integer
    Dim intPrintJobCount As Integer
    Dim PDFCreator1
   
    Set PDFCreator1 = CreateObject("PDFCreator.clsPDFCreator")
   
    'Do not show the PDFCreator object on the task bar
    PDFCreator1.cVisible = False
    
     'Define the PDFCreator options
    With PDFCreator1
      .cStart "/NoProcessingAtStartup"
       
      'Stop PDFCreator Printer to capture all jobs sent to printer queue.
      .cPrinterStop = True
       
      .cOption("UseAutosave") = 1
      .cOption("UseAutosaveDirectory") = 1
      .cOption("AutosaveDirectory") = strPDFPath
      .cOption("AutosaveFilename") = sPDFName
       
      .cOption("AutosaveFormat") = 0    ' 0 = PDF Format
       
      .cOption("PDFDisallowModifyContents") = 1
      
      .cClearCache
     
      intPrintJobCount = 0
     
      If blnCoverSheetYesNo = True Then
     
            'Print the cover page report
            PrintFaxEmailAccessReport "FaxCoverSheet"
           
            'Wait until the print job has entered the print queue
            intPrintJobCount = intPrintJobCount + 1
            Do Until PDFCreator1.cCountOfPrintjobs = intPrintJobCount
                DoEvents
            Loop

      End If

      'Print the main report
      PrintFaxEmailAccessReport sReportName
     
      'Wait until the print job has entered the print queue
      intPrintJobCount = intPrintJobCount + 1
      Do Until PDFCreator1.cCountOfPrintjobs = intPrintJobCount
          DoEvents
      Loop
     
      'Merge jobs
      .cCombineAll
     
      'Wait until jobs have been combined
      Do Until PDFCreator1.cCountOfPrintjobs = 1
          DoEvents
      Loop
     
      'Start printing the final PDF.
      .cPrinterStop = False
    End With
    
    'Wait until the print job has been released.
    Do Until PDFCreator1.cCountOfPrintjobs = 0
        DoEvents
    Loop
   
    PDFCreator1.cClose
   
    'Wait until the program is finished. The process may still exist in task manager.
    While PDFCreator1.cProgramIsRunning
        DoEvents
    Wend
   
    'This will now cause the process to disappear from the task manager.
    Set PDFCreator1 = Nothing

    'Shell out to run AcrobatReader for preview
    Dim ret As Long
    ret = shell(Parent.gstrAcrobatReaderPath + " " + Chr(34) + strPDFPath + strDocumentFileName + Chr(34), vbNormalFocus)
        
    Exit Sub

errPDFCreator:
    ... 
End Sub

 


The trailing 426 bytes are:

 

 


/pdfmark where {pop} {userdict /pdfmark /cleartomark load put} ifelse
[


/Author
/CreationDate (D:20110223104542-05'00')
/Creator
/Keywords ()
/ModDate (D:20110223104542-05'00')
/Subject ()
/Title
/DOCINFO pdfmark
%%EOF

Well, more testing has revealed the culprit.  This code is not a reliable way to determine if the spooler is done:

    Do Until PDFCreator1.cCountOfPrintjobs = 0
        DoEvents
    Loop

To fix the problem of calling too quickly .cClose I am going to add a loop looking for the ~PSxxxx.tmp file in the temp folder. ... That is unless the authors of this tool can provide a foolproof API to determine that it is now safe to call .cClose.

After some more testing the culprit is that this loop is an unreliable indicator that it is safe to call .cClose:

    Do Until PDFCreator1.cCountOfPrintjobs = 0
        DoEvents
    Loop
 

I am going to change this loop to detect if the temp file ~PSxxxx.tmp has been deleted .... unless the authors of this tool can provide a better API.