Happy New 2007
because I have lost a lot of time debuging problems caused by not checking the exit codes on UnlockKey and LoadFromFile function I decoded to publish some helper to help you in writing VB6 QuickPDF based applications.
Wen you want to create a new QuickPDF instance use:
CreateQuickPDF function
and when you want to load a new PDF document and
unload the current one (usefull with single document applications) use:
LoadDocument procedure.
Both functions/procedures throw errors when something fails !!!
Happy Programming :-)
Marian
<Module name="QPDF helper">
Attribute VB_Name = "QPDF" Option Explicit Public Const qPDFLicenseKey = "your license key"
' Create a new QuickPDF instance Public Function CreateQuickPDF() As iSED.QuickPDF Dim QP As iSED.QuickPDF
Set QP = CreateObject("iSED.QuickPDF") If QP.UnlockKey(qPDFLicenseKey) = 0 Then Err.Raise vbObjectError, , "Cannot unlock quickpdf library: " & QP.LicenseInfo End If
Set CreateQuickPDF = QP End Function
' Load a new PDF document Public Sub LoadDocument(ByRef QP As iSED.QuickPDF, ByVal FileName As String) Dim nOldDoc As Long Dim nNewDoc As Long
nOldDoc = QP.SelectedDocument If QP.LoadFromFile(FileName) = 0 Then Err.Raise vbObjectError, , "Cannot open pdf document: " & FileName End If
nNewDoc = QP.SelectedDocument If QP.Encrypted > 0 Then If QP.Unencrypt = 0 Then Call QP.RemoveDocument(nNewDoc) Call QP.SelectDocument(nOldDoc) Err.Raise vbObjectError, , "Document cannot be decrypted" End If End If Call QP.RemoveDocument(nOldDoc) ' discard previous document End Sub </Module>
<Module name="test QPDF module">
Public Sub PrintTest() Call PrintDocument( _
App.Path & "\some file.pdf", _
"SomePrinter device") End Sub
Public Sub PrintDocument(ByVal FileName As String, ByVal PrintDevice As String) On Error GoTo err_Main Dim QP As iSED.QuickPDF Dim Printeroptions As Long Dim PrintResult As Long ' Create quickPDF object Set QP = CreateQuickPDF ' Load PDF document Call LoadDocument(QP, FileName) ' Print document Printeroptions = QP.PrintOptions(0, 0, "PDF output") PrintResult = QP.PrintDocument(PrintDevice, 1, QP.PageCount, Printeroptions)
MsgBox "Finished" exit_Main: Set QP = Nothing Exit Sub err_Main: MsgBox Err.Description Resume exit_Main End Sub </Module>
|