Code: Select all
Const strActivationCode = "xxx"
Const strLicensedTo = "AMS Services Inc."
Const strPDFPrinterName = "Test PDF Converter"
' ******************** other Declarations *******************
Private Declare Function ShellExecute _
Lib "shell32.dll" _
Alias "ShellExecuteA" _
(ByVal hWnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Declare Function GetDesktopWindow _
Lib "user32" () As Long
Public Function CreatePDFPrinter() As Long
Dim X As Printer
' 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"
End
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
SetDefaultFileName hPDF1, "c:\temp\text1.pdf"
'End If
'Need to Enable Printer before every print job
EnablePrinter hPDF1, strLicensedTo, strActivationCode"
End Select
Next X
CreatePDFPrinter = hPDF1
End Function
Private Sub Command1_Click()
CommonDialog1.ShowOpen
Text1.Text = CommonDialog1.Filename
End Sub
Private Sub Command2_Click()
MousePointer = vbHourglass
hPDF1 = CreatePDFPrinter
SetDefaultPrinter (hPDF1)
ShellExecute GetDesktopWindow, "Print", Me.Text1.Text, "", "C:\temp", 0
RestoreDefaultPrinter (hPDF1)
MousePointer = vbDefault
End Sub
-- Dana[/code]