Print Page | Close Window

Propper Usage of QuickPDF in Visual Basic 6

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: Sample Code
Forum Description: Share Debenu Quick PDF Library sample code with other forum members
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=595
Printed Date: 30 Apr 24 at 6:05AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Propper Usage of QuickPDF in Visual Basic 6
Posted By: marian_pascalau
Subject: Propper Usage of QuickPDF in Visual Basic 6
Date Posted: 02 Jan 07 at 6:37AM

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>



Replies:
Posted By: Michel_K17
Date Posted: 02 Jan 07 at 10:11PM
Nice! Smile

-------------
Michel



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk