Code: Select all
Public Function CreatePDFPrinter() As Long
Dim X As Printer
Dim pPhnxPrinter As CPhnxPrinter 'this may no longer be needed
Dim m_strDeviceName As String
' create pdf converter if it doesn't exist - if it does, attach to it
hPDF1 = PDFDriverInit("ABK PDF Converter")
' following call leaves pdf converter on system even if 'DriverEnd' called
hPDF1 = DriverInit("ABK PDF Converter")
If hPDF1 = 0 Then
MsgBox "Cannot initialize PDF Converter"
Call EndProgram
End If
' set file name options
For Each X In Printers
Select Case X.DeviceName
Case "ABK PDF Converter"
Set Printer = X
If GetDocPrintPDFPageCompression = 0 Then
SetFileNameOptions hPDF1, NoPrompt + UseFileName + Concatenate + DisableCompression
Else
SetFileNameOptions hPDF1, NoPrompt + UseFileName + Concatenate
End If
'If bCreatePDF = True Then
SetVerticalMargin hPDF1, GetDocPrintPDFVerticalMargin
SetHorizontalMargin hPDF1, GetDocPrintPDFHorizontalMargin
SetResolution hPDF1, 600
SetDefaultConfig hPDF1
'End If
'Need to Enable Printer before every print job
EnablePrinter hPDF1, "strLicensedTo", strLicenseCode
End Select
Next X
CreatePDFPrinter = hPDF1
End Function
However, if I create a reference to the dll (Project/References/browse) and then have code as follows, a zero rather than a handle is returned. The program does PDF as desired, but I expected to get back a non-zero number. The documentation says to expect a null if unsuccessful and a handle if successful. Why aren't I getting back a handle? I would not expect the handle to always be zero - which is what I get back.
Code: Select all
Option Explicit
Public WithEvents pdfEvent As CDIntfEx.CDIntfEx
Public Function CreatePDFPrinter() As Long
Set pdfEvent = New CDIntfEx.CDIntfEx
hPDF1 = pdfEvent.PDFDriverInit(PDFPrinter)
hPDF1 = pdfEvent.DriverInit(PDFPrinter)
pdfEvent.CaptureEvents (1)
If GetDocPrintPDFPageCompression = 0 Then
pdfEvent.FileNameOptions = NoPrompt + UseFileName + Concatenate + DisableCompression
Else
pdfEvent.FileNameOptions = NoPrompt + UseFileName + Concatenate
End If
pdfEvent.VerticalMargin = GetDocPrintPDFVerticalMargin
pdfEvent.HorizontalMargin = GetDocPrintPDFHorizontalMargin
pdfEvent.Resolution = 600
pdfEvent.SetDefaultConfig
pdfEvent.EnablePrinter strLicenseTo, strActivationCode
pdfEvent.SetDefaultPrinter
CreatePDFPrinter = hPDF1
End Function
-- Dana