I am using version 1.0.2 of PDFCreator (since 2010) in my VB6 application and i never experienced serious trouble with my customers.
In my code i use Crystal Reports and the user can print reports to PDF using PDFCreator COM interface.
Now i am releasing a major update of my software and i think it is the right time to update PDFCreator to the last version (1.7.2). I have updated my computer (the one where i compile the application) and all is fine: all the functionality is ok in the compiled app.
BUT ...the same executable on a Windows 7 Pro - where the application was working without any problem with 1.0.2 - shows the monitor and waits indefinitely. I have no idea of what is wrong with my code (may be someting has changed between 1.0.2 and 1.7.2?)
It has to be clear that i have not modified the original vb6 code in any way - it is exactly the same it was when i started using PDFCreator!
Here is my code:
Private WithEvents pdfJob As PDFCreator.clsPDFCreator
Private pdfErr As clsPDFCreatorError
Private blnEndPrt As Boolean
Private Sub doStartPrintJob()
On Error Resume Next
Set pdfErr = New clsPDFCreatorError
Set pdfJob = New PDFCreator.clsPDFCreator
If Err.Number <> 0 Then
doShowMsg "Unable to instatiate PDFCreator"
Exit Sub
End If
If pdfJob.cStart("/NoProcessingAtStartup") = False Then
doShowMsg "Unable to start PDFCreator"
Exit Sub
End If
On Error GoTo PANIC
With pdfJob
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = "C:\Tmp\"
.cOption("AutosaveFilename") = "TestFile"
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cOption("AutosaveStartStandardProgram") = 0
.cClearCache
End With
Call doPDF
PANIC:
On Error Resume Next
' reset PDFCreator
pdfJob.cClose: Set pdfJob = Nothing
End Sub
Private Sub doPDF()
Dim err_lev As Integer
Dim s As String, t As String, mstrErrMsg As String
On Error GoTo PANIC
' Report1 is a Crystal Report object
Report1.Destination = 1
Report1.DiscardSavedData = True
Report1.ProgressDialog = False
'Print the document to PDF
doGetPDFPrinter s, t
Report1.Printername = "PDFCreator"
Report1.PrinterDriver = s
Report1.PrinterPort = t
err_lev = Report1.PrintReport ' do report with Crystal Report
'Wait until the print job has entered the print queue
' Do Until pdfJob.cCountOfPrintjobs = 1: DoEvents: Loop
pdfJob.cPrinterStop = False
'Wait until PDF creator is finished then release the objects
' Do Until pdfJob.cCountOfPrintjobs = 0: DoEvents: Loop
Do Until blnEndPrt: DoEvents: Loop
Report1.ReportFileName = ""
If err_lev > 0 Then
doShowMsg CStr(Report1.LastErrorNumber) & " - " & Report1.LastErrorString
End If
Exit Sub
PANIC:
doShowMsg CStr(Err.Number) & " - " & Err.Description
End Sub
Private Sub doShowMsg(ByVal strMsg As String)
lblMsg = strMsg: lblMsg.Refresh
End Sub
Private Sub doGetPDFPrinter(ByRef sDrvName As String, ByRef sPort As String)
Dim objPrt As Printer
For Each objPrt In Printers
If objPrt.DeviceName = "PDFCreator" Then
sDrvName = objPrt.DriverName
sPort = objPrt.Port
Exit For
End If
Next
End Sub
Private Sub pdfJob_eError()
Set pdfErr = pdfJob.cError
blnEndPrt = True
doShowMsg "Err. [" & pdfErr.Number & "]: " & pdfErr.Description
End Sub
Private Sub pdfJob_eReady()
pdfJob.cPrinterStop = True
blnEndPrt = True
End Sub
Maybe someone knows a trick to escape from this maze?