Powerful all-in-one PDF library for .NET
VS 2005/2008/2010/2012/2013

A PDF Printer Demo For PDFOne .NET

Learn how to print a PDF document in .NET.
By V. Subhash

Printing a PDF document using PDFOne is very simple - create a PDFPrinter instance, load the PDF document, and call the "Print" method.

The PDF printer component exposes a System.Drawing.Printing.PrinterSettings property for full .NET printing support. This allows your .NET application to enumerate available printers, paper sizes, media trays and other settings and choose appropriate ones for PDF print jobs. Apart from this, the PDF printer component has numerous printing settings of its own, such as the ability to:

The following code snippet illustrates how to a PDF document in C# using PDFOne .NET.

using System;
using System.Collections.Generic;
using System.Text;
using Gnostice.PDFOne;
using Gnostice.PDFOne.PDFPrinter;
using System.Drawing.Printing;

class PDF_Printer_Demo {

  static void Main(string[] args) {
    PDFPrinter PDFPrinter1
        = new PDFPrinter("your license key");

        += new PasswordRequiredEventHandler(PDFPrinter1_PasswordRequired);
        += new PrintErrorDelegate(PDFPrinter1_PrintError);
        += new RenderErrorHandler(PDFPrinter1_RenderError);
        +=new PrintPageDelegate(PDFPrinter1_AfterPrintPage);

    try {
      Console.Write("Opening document ... ");
      // Load document for printing

      // Specify print settings
      PDFPrinter1.AutoCenter = true;
      PDFPrinter1.AutoRotate = true;
      PDFPrinter1.PageScaleType = PrintScaleType.None;
      PDFPrinter1.PrintOptions.PrintRange = PrintRange.Selection;
      PDFPrinter1.SelectedPages = "2,4";

      Console.Write("Selecting printer ... ");
      // Select first one among installed printers
          = (String) PrinterSettings.InstalledPrinters[0];

      Console.WriteLine("Sending print output to selected printer [" +
                    PDFPrinter1.PrintOptions.PrinterName + "] ... ");
      // Start printing
      Console.Write("\r                                ");

    } catch (Exception Exception1) {
      Console.WriteLine("\nError: " + Exception1.Message);
    } finally {
      try {
        Console.Write("Closing document ... ");
        // Close printed document
      } catch (Exception Exception2) {
         Console.WriteLine("\nError: " + Exception2.Message);
      } finally {
        // Clean up

        Console.WriteLine("Press Enter to exit.");

  // Event handler for PDFPrinter.PrintError
  private static void PDFPrinter1_PrintError(
      object sender,
      int pageNumber,
      Exception e) {
    Console.WriteLine("\nError: While creating print output on page #" +
                      pageNumber.ToString() +
                      "\nOriginal Error Message: " +

  // Event handler for PDFPrinter.RenderError
  private static void PDFPrinter1_RenderError(
      object sender,
      int pageNum,
      Exception renderError,
      ref bool continueRendering)  {
    Console.WriteLine("\n\nError: While rendering page #" +
                      pageNum.ToString() + " on printer." +
                      "\nOriginal Error Message: " +

  // Event handler for PDFPrinter.AfterPrintPage
  private static void PDFPrinter1_AfterPrintPage(
      object sender,
      int pageNumber,
      PrintPageEventArgs e) {
    // Clear the current line
    Console.Write("\r                                ");
    // Write number of last page that was printed
    Console.Write("\rPrinting page #" + pageNumber.ToString());

  // Event handler for PDFPrinter.PasswordRequired
  private static void PDFPrinter1_PasswordRequired(
      object sender,
      ref string password,
      ref bool continueLoading) {
    // Prompt for password
    Console.WriteLine("\n\nEnter a password to open this document: ");
    // Obtain password entered by user
    String sPassword = Console.In.ReadLine();

    // Open document with obtained password
    password = sPassword;
    continueLoading = true;



Our .NET Developer Tools
XtremeDocumentStudio .NET

Multi-format document-processing component suite for .NET developers.


A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

Our Delphi/C++Builder developer tools
XtremeDocumentStudio Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

Our Java developer tools
XtremeDocumentStudio (for Java)

Multi-format document-processing component suite for Java developers.

PDFOne (for Java)

A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications.

Our Platform-Agnostic Cloud and On-Premises APIs

Cloud-hosted and On-Premises REST-based document-processing and document-viewing APIs

Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2016 Gnostice Information Technologies Private Limited. All rights reserved.