Working with PDF printing - Facades

Printing PDF File to Default Printer using Printer and Page Settings

First, the document is converted into image, and then, printed on the printer. Create an instance of the PdfViewer class, that enables printing a PDF file to the default printer, use the BindPdf method to open the document into it, and change necessary settings. This example uses A4 format, portrait orientation. In the PrinterSettings, first of all, the name of the printer, to which printing goes, should be set. Or else it will print to the default printer. Next, put down the required number of copies.

In order to display a print dialog, use the following code snippet:

There are printers that print to a file. To use them, set the name of the virtual printer, and, analogous to the previous example, make the settings.

Hiding Print Dialog

Aspose.PDF for .NET supports hiding the print dialog. For this, use the PrintPageDialog property.

The following code snippet shows how to hide the print dialog.

Printing Color PDF to XPS File as Grayscale

A color PDF document can be printed to an XPS printer as grayscale, using PdfViewer. In order to achieve that, set the property PdfViewer.PrintAsGrayscale to true. The following code snippet demonstrates the usage of the PdfViewer.PrintAsGrayscale property.

PDF to PostScript conversion

The PdfViewer class provides the capability to print PDF documents and with the help of this class, one can also convert PDF files to PostScript format. To convert a PDF file into PostScript, first install any PS printer and just print to file with the help of the PdfViewer.

The following code snippet shows how to print and convert a PDF to PostScript format.

Checking Print Job Status

A PDF file can be printed to a physical printer as well as to the Microsoft XPS Document Writer, without showing a print dialog, using the PdfViewer class. When printing large PDF files, the process might take a long time so the user might not be certain whether the printing process completed or encountered an issue. To determine the status of a printing job, use the PrintStatus property. The following code snippet shows how to print the PDF file to an XPS file and get the printing status.

Printing pages in Simplex and Duplex mode

In a particular printing job, the pages of PDF document can either be printed in Duplex or in Simplex mode but you cannot print some pages as simplex and some pages as duplex within a single print job. However in order to accomplish the requirement, different page ranges and PrintingJobSettings object can be used. The following code snippet shows how to print some pages of PDF file in Simplex and some pages in Duplex mode.