This article describes how to print PDF to PDF with C#. You will get details on setting up the development environment, a list of steps, and a sample code for using an Adobe PDF printer with C#. It will also share the properties to set the printer settings, page settings, and printing attributes.
Steps to Print to PDF Virtual Printer with C#
- Set the environment to use Aspose.PDF for .NET to print with a soft printer
- Instantiate the PDFViewer class object
- Load the source PDF file by binding it with the viewer
- Set the printing attributes
- Create the PrinterSettings and PageSettings class objects and set the desired properties
- Print the document to the PDF printer
- Close the PDF file
These steps share details for using a virtual PDF printer with C#. Instantiate the PdfViewer class object, bind the source PDF file, and set the printing attributes. Create objects of the PrinterSettings and PageSettings class and set the printer name, page size, and margins before printing the document using the PrintDocumentWithSettings() method in the PDFViewer class.
Code to Print to PDF Printer with C#
This sample code demonstrates how to develop the virtual printer software with C#. You can set additional properties in the PDFViewer, such as coordinate type, horizontal alignment, grayscale printing option, and resolution if needed. You may omit setting the paper size and margins while using the default settings.
This tutorial has shown us how to use the Adobe PDF virtual printer with C#. If you want to rotate the PDF, refer to the article on how to rotate PDF using C#.