Limited time promo

PDF Reports - SDK sample

English en

This article applies only to novaPDF. If you don't have it yet, you must download it first.

Download now Buy licenses
Feb 22, 2019
We strive to keep our articles as accurate as possible. If you notice any inconsistencies or outdated info please let us know.
Sample SDK code (.cpp) for printing "Hello World" text to the novaPDF Printer from remote computer.
PDF Reports Sample is an Access database with one table and one form. On the form you can set several options for the novaPDF and then press a button to generate a PDF file. A report is made on the table and it is sent to novaPDF. It demonstrates the basic use of the INovaPDFOptions interface. The printing job is made using the object Application.Printer.
Basically the sample creates a new profile calledAccess Profile, sets the new profile as active, sets the user options from form controls, opens and prints a report, and restores original printer settings.
Note: To be able to use the samples you must install novaPDF SDK as samples work only with it. Download it here: novaPDF SDK.

Source Code

Option Compare Database
Option Explicit

Private objPDF As Object

Const strIAProfile As String = "Access Profile"
Const strPDFDriver As String = "<%SDK_SAMPLE_PRINTER%>"
Const bIAPublicProfile As Long = 0

Private Sub cmdCreatePDF_Click()
    On Error GoTo Error_cmdCreatePDF_Click

    Dim strActiveProfileId As String
    Dim strNewProfileId As String
    Dim strDefaultPrinter As String
    ' create the NovaPdfOptions object
    Dim objPDF As New NovaPdfOptions80
    ' initialize the NovaPdfOptions object to use with a printer licensed for SDK
    objPDF.Initialize2 strPDFDriver ""
    ' Store the Default Printer.  * Note - Access cannot use the objPDF.SetDefaultPrinter command as it does not
    ' update Access internally fast enough.  You must use the Application.Printer command instead.
    strDefaultPrinter = Application.Printer.DeviceName
    ' Get the Active Profile
    objPDF.GetActiveProfile2 strActiveProfileId
    ' Add new profile
    objPDF.AddProfile2 strProfileName, bIAPublicProfile, strNewProfileId
    'Load the profile
    objPDF.LoadProfile2 strNewProfileId
    With Me
        ' Set save options
        If !optSaveOptions Then
        End If
        objPDF.SetOptionString2 NOVAPDF_SAVE_FOLDER, !txtSaveFolder
        objPDF.SetOptionString2 NOVAPDF_SAVE_FILE_NAME, !txtFilename
        objPDF.SetOptionLong NOVAPDF_SAVE_FILEEXIST_ACTION, !cboWhenFileExists
        ' After Save Action
        objPDF.SetOptionBool NOVAPDF_ACTION_DEFAULT_VIEWER, !chkOpenViewer

        ' .... other options

        'save options

        ' Set the PDF print driver.
        objPDF.SetActiveProfile2 strNewProfileId

        ' Set the Default printer.
        Set Application.Printer = Application.Printers(strPDFDriver)

        ' Run the selected report and create a PDF file.
        DoCmd.OpenReport "rptSMZipCode"

        ' Return to previous settings
        objPDF.SetActiveProfile2 strActiveProfileId
        objPDF.DeleteProfile2 strNewProfileId

        ' Restore the Default Printer.
        Set Application.Printer = Application.Printers(strDefaultPrinter)
    End With

    Set objPDF = Nothing
    Exit Sub
    Debug.Print Err.Number & ":" & Err.Description
    Resume Next
End Sub