Limited time promo

CSharp Sample - Override Options


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

Download now Buy licenses
Mar 28, 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

using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
// the novapiLib package must be added as a COM reference
using novapiLib11;
using Globals;

namespace Override_Options
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    class Class1
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        public static string PRINTER_NAME = "novaPDF SDK 11";
        public static string PDF_TEXT = "Override Options";
        public static string PDF_FILE_NAME = "OverrideOptions.pdf";

        static void Main(string[] args)
                // create the NovaPdfOptions object
                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, "");

                //Ovveride options from active profile
                //Save options
                //do not show prompt save dialog
                pNova.SetOverrideOptionLong(NovaOptions.NOVAPDF_OVERRIDE_SAVE_TYPE, (int)SaveDlgType.PROMPT_SAVE_NONE);
                //save the pdf in next folder
                pNova.SetOverrideOptionLong(NovaOptions.NOVAPDF_OVERRIDE_SAVE_FOLDER_TYPE, (int)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, (int)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, (int)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, (int)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, (int)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");

                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");

                // print a test page, using the previously set active profile settings
                using (PrintDocument pd = new PrintDocument())
                    pd.PrinterSettings.PrinterName = PRINTER_NAME;
                    pd.PrintPage += new PrintPageEventHandler(PrintPageFunction);
                    pd.DefaultPageSettings.PaperSize = GetPaperSize("A4");

                int bTimeout;
                pNova.WaitForNovaEvent(120000, out bTimeout);
            catch (System.Runtime.InteropServices.COMException e)
            catch (Exception e)

        //find a predefined paper size
        private static PaperSize GetPaperSize(string Name)
            PaperSize size1 = null;
            Name = Name.ToUpper();
            PrinterSettings settings = new PrinterSettings();
            foreach (PaperSize size in settings.PaperSizes)
                if (size.Kind.ToString().ToUpper() == Name)
                    size1 = size;
            return size1;

        // and finally the function that actually prints the page
        private static void PrintPageFunction(object sender, PrintPageEventArgs ev)
            string str = "novaPDF says Hello World from C#";
            Font font = new Font("Arial", 16);
            Brush brush = new SolidBrush(Color.Black);
            ev.Graphics.DrawString(str, font, brush, 20.0f, 20.0f);
            ev.HasMorePages = false;