Limited time promo

VBNet Sample - Override Options

English

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

Download now Buy licenses
Mar 29, 2022
novaPDF 11.x
We strive to keep our help as accurate as possible. If you notice any inconsistencies or outdated info please let us know.
Override Options sample is a simple Windows console application that demonstrates the basic use of the INovaPDFOptions interface, without using profiles options. Instead of creating a profile and setting options in the profile, the sample uses SetOverrideOptions... functions to quickly set some options that will overwrite active profile settings. This is useful if you have a simple application where you just wish to change the pdf file name, email address or other simple options for each printed document.
There is a limited set of options that can be set with SetOverrideOptions... functions, usually settings that users can also change from the Save As dialog or the other prompt dialogs that can be shown before printing a document. If you need more complex settings, like adding a watermark, overlay or signature you have to configure them in a profile.
You can combine usage of profiles and override options functions. For instance you can create a profile with a watermark that is set as active and then use the override function just to change the file name for each document.
Once set, override options are taken in account for all printed documents until they are removed with DeleteOverrideOptions function.
The sample prints one page with a simple text to the novaPDF SDK and generates a "OverrideOptions.pdf" file in the C:\temp folder.

Source code

Imports System
Imports System.Drawing
Imports System.Drawing.Printing
Imports System.Windows.Forms
' the novapiLib package must be added as a COM reference
Imports novapiLib11

Module Module1
    '    <summary>
    '    The    main entry point for the application.
    '    </summary>
    Const PRINTER_NAME As String = "novaPDF SDK 11"
    Const PDF_FILE_NAME As String = "OverrideOptions.pdf"

    Sub Main()
        Try
            ' create the NovaPdfOptions object
              Dim pNova As NovaPdfOptions11
                pNova = New NovaPdfOptions11

            ' initialize the NovaPdfOptions object
            ' if you have an application license for novaPDF SDK, 
              ' pass the license key to the Initialize() function
                pNova.Initialize(PRINTER_NAME, "")

                'Override options from active profile

              'Save options
                'do not show prompt save dialog
                pNova.SetOverrideOptionLong(NovaOptions.NOVAPDF_OVERRIDE_SAVE_TYPE, SaveDlgType.PROMPT_SAVE_NONE)
              'save the pdf in next folder
                pNova.SetOverrideOptionLong(NovaOptions.NOVAPDF_OVERRIDE_SAVE_FOLDER_TYPE, SaveFolder.SAVEFOLDER_CUSTOM)
                pNova.SetOverrideOptionString(NovaOptions.NOVAPDF_OVERRIDE_SAVE_FOLDER, "C:\\temp")
              pNova.SetOverrideOptionString(NovaOptions.NOVAPDF_OVERRIDE_SAVE_FILE, PDF_FILE_NAME)
                'access folder, if restricted
                pNova.SetOverrideOptionEncryptedString(NovaOptions.NOVAPDF_OVERRIDE_SAVE_USER, "user")
                pNova.SetOverrideOptionEncryptedString(NovaOptions.NOVAPDF_OVERRIDE_SAVE_PASSWORD, "password")
              'if a file with the same neme already exists
                pNova.SetOverrideOptionLong(NovaOptions.NOVAPDF_OVERRIDE_SAVE_CONFLICT, SaveFileConflictType.FILE_CONFLICT_STRATEGY_OVERWRITE)

              'disable open PDF in viewer
                'pNova.SetOverrideOptionBool(NovaOptions.NOVAPDF_OVERRIDE_OPEN_VIEWER, 0)

              'Embed fonts
                pNova.SetOverrideOptionBool(NovaOptions.NOVAPDF_OVERRIDE_EMBEDFONTS, 1)

              'Set compression level
                'pNova.SetOverrideOptionLong(NovaOptions.NOVAPDF_OVERRIDE_COMPRESSION, CompressionOverride.COMPRESSION_HIGHQUALITY)

              'Merge PDF
                'Enable merge

              'pNova.SetOverrideOptionBool(NovaOptions.NOVAPDF_OVERRIDE_MERGE_PDF, 1)
                'Merge with the same file, if the file exists in destination OR merge with another file
                'pNova.SetOverrideOptionLong(NovaOptions.NOVAPDF_OVERRIDE_MERGE_FILE_TYPE, MergeFile.MERGE_FILE_OTHER)
              'Append to existing PDF, insert at the beginning or insert at a page number
                'pNova.SetOverrideOptionLong(NovaOptions.NOVAPDF_OVERRIDE_MERGE_TYPE, MergeType.MERGE_TYPE_APPEND)
                'if merge with other file, specify file name (and path)
              'pNova.SetOverrideOptionString(NovaOptions.NOVAPDF_OVERRIDE_MERGE_FILE, "invoice-text.pdf")
                'if merge type is set to insert at page number
                'pNova.SetOverrideOptionLong(NovaOptions.NOVAPDF_OVERRIDE_INSERT_PAGENO, 1)
              'if the existing PDF is encrypted
                'pNova.SetOverrideOptionEncryptedString(NovaOptions.NOVAPDF_OVERRIDE_PDF_PASSWORD, "password")

                'Document info
                pNova.SetOverrideOptionBool(NovaOptions.NOVAPDF_OVERRIDE_DOC_INFO, 1)
              pNova.SetOverrideOptionString(NovaOptions.NOVAPDF_OVERRIDE_DOC_TITLE, "sdk title")
                pNova.SetOverrideOptionString(NovaOptions.NOVAPDF_OVERRIDE_DOC_SUBJECT, "sdk subject")
                pNova.SetOverrideOptionString(NovaOptions.NOVAPDF_OVERRIDE_DOC_AUTHOR, "sdk author")
              pNova.SetOverrideOptionString(NovaOptions.NOVAPDF_OVERRIDE_DOC_KEY, "sdk key")
                pNova.SetOverrideOptionString(NovaOptions.NOVAPDF_OVERRIDE_DOC_CREATOR, "sdk creator")

                'Encrypt PDF
                'pNova.SetOverrideOptionBool(NovaOptions.NOVAPDF_OVERRIDE_SECURITY, 1)
              'pNova.SetOverrideOptionEncryptedString(NovaOptions.NOVAPDF_OVERRIDE_SECURITY_U, "user")
                'pNova.SetOverrideOptionEncryptedString(NovaOptions.NOVAPDF_OVERRIDE_SECURITY_O, "owner")

                'Email
              pNova.SetOverrideOptionBool(NovaOptions.NOVAPDF_OVERRIDE_SEND_EMAIL, 1)
                pNova.SetOverrideOptionString(NovaOptions.NOVAPDF_OVERRIDE_REC_TO, "to")
                pNova.SetOverrideOptionString(NovaOptions.NOVAPDF_OVERRIDE_REC_FROM, "from")
              pNova.SetOverrideOptionString(NovaOptions.NOVAPDF_OVERRIDE_REC_CC, "cc")
                pNova.SetOverrideOptionString(NovaOptions.NOVAPDF_OVERRIDE_REC_BCC, "bcc")

                pNova.RegisterNovaEvent(NovaEvents.NOVAPDF_EVENT_ACTIONS)

            ' print a test    page
            Dim pd As PrintDocument = New PrintDocument
            pd.PrinterSettings.PrinterName = PRINTER_NAME
            AddHandler pd.PrintPage, AddressOf PrintPageFunction
                pd.Print()

              Dim bTimeout As Integer
                pNova.WaitForNovaEvent(120000, bTimeout)

        Catch e As System.Runtime.InteropServices.COMException
                MessageBox.Show(e.Message)
        Catch e As Exception
            MessageBox.Show(e.Message)
        End Try
    End Sub

    ' and finally the function that actually prints the page
    Private Sub PrintPageFunction(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
        Dim str As String = "novaPDF says Hello World from VB.Net"
        Dim font As Font = New Font("Arial", 16)
        Dim brush As Brush = New SolidBrush(Color.Black)
        ev.Graphics.DrawString(str, font, brush, 20.0!, 20.0!)
        ev.HasMorePages = False
    End Sub

End Module