COM cleanup

I'm using the PDFCreator COM object in a VB.NET service.  I had to do a standard installation to get the PDFCreator working, but it does create the .tif files now.  However, now when I try to do  _PDFCreator.cClose()  the application appears to just hang.  Has anyone ran into this before? 

Any help would be appreciated.

Thanks!

This is a common problem.  There were a few suggestions in the old forums, which had varying results for different people.  I posted a solution that I thought would work in all situations - unfortunately, I didn't get a chance to see if anyone commented on my solution before the forums were lost.

I don't remember exactly what I found as the "magic bullet" that fixed the problem.

I added a few DoEvents and some wait timers ...  I think specifically it was the placement of a DoEvent (VB6) that seemed to resolve the issue. 

Sorry I can't be more help.  I had a pretty good write up about this problem before the Forums got fragged.

Here is my code for Word 2003 VBA COM:

 

Private WithEvents PDFCreator1 As PDFCreator.clsPDFCreator

Private FileSaved As Boolean, ReadyState As Boolean, DefaultPrinter As String, LoopCount As Long

Public Sub SaveWholeDocumentAsPDF(Filename As String)
    FileSaved = False
    If Len(ActiveDocument.Path) = 0 Then
        MsgBox "Please save the document first!", vbExclamation
        Exit Sub
    End If
    Set PDFCreator1 = New clsPDFCreator
    With PDFCreator1
        If .cStart("/NoProcessingAtStartup") = False Then
        MsgBox "Can't initialize PDFCreator."
    Exit Sub
    End If
        DefaultPrinter = ActivePrinter
        SetPrinter "PDFCreator"
    End With

    With PDFCreator1
        .cOption("UseAutosave") = 1
        .cOption("UseAutosaveDirectory") = 1
        .cOption("AutosaveDirectory") = ActiveDocument.Path
        .cOption("AutosaveFilename") = Filename
        .cOption("AutosaveFormat") = 0                            ' 0 = PDF
        .cOption("Papersize") = "Letter"
        .cClearCache
        DoEvents
        ActiveDocument.PrintOut Background:=False
        DoEvents
        .cPrinterStop = False
    End With

    SetPrinter DefaultPrinter
    LoopCount = 0
    Do Until FileSaved = True
        If LoopCount >= 100 Then 'End loop after approx 25 seconds
            MsgBox "Loop has run for more than 25 seconds - Cannot close PDFCreator"
            PDFCreator1.cPrinterStop = True
            PDFCreator1.cClearCache
            Exit Do
        End If
        DoEvents
        Sleep 250
        LoopCount = LoopCount + 1
    Loop
    DoEvents 'Just to be ABSOLUTELY sure that PDFCreator is ready to close!
    Sleep 250 'Wait another 1/4 of a second
    PDFCreator1.cClose
    Set PDFCreator1 = Nothing
    Sleep 250
    DoEvents
End Sub

Private Sub PDFCreator1_eError()
    MsgBox "ERROR [" & PDFCreator1.cErrorDetail("Number") & "]: " & PDFCreator1.cErrorDetail("Description")
End Sub

Private Sub PDFCreator1_eReady()
    'File was saved
    FileSaved = True
    PDFCreator1.cPrinterStop = True
End Sub

Private Sub SetPrinter(Printername As String)
    With Dialogs(wdDialogFilePrintSetup)
        .Printer = Printername
'        .Printer.PaperSize = wdPaperLetter
        .DoNotSetAsSysDefault = True
        .Execute
    End With
End Sub
 

 Yes, the hang-on-cClose problem is the major one left for us. We are actually writing settings to the registry directly instead of using the COM interface, and that works fine. 

 

If we close without a delay prior, it reliably hangs. If we wait, as now, 2000 milliseconds it seems to hang "only" about 1 times out of 10.

Hello,

the old content is not lost, you can find it here:

http://www.pdfforge.org/files/old_forum/index.html

(as stated in the new forums thread)

kind regards,
Philip

 1.)  Old content has been reposted in the new forum.  Try your seach again.

 2.)  I don't know much about VB.NET,. but I was running into a similar problem with Python which seemed to work much better when I wrapped up the entire functions inside another class.  basically I had to remove the PDFCreator references from any public function so that they were destroyed upon completing.  When I was testing the code I always had trouble, once I integrated it into a larger program things started working better, but not perfectly as expected :-(