Print PDF using C#

Print PDF documents. Use Aspose.PDF for .NET to modify PDF files programmatically

How to Print PDF Using C# Library

In order to print PDF file, we’ll use Aspose.PDF for .NET API which is a feature-rich, powerful and easy to use document manipulation API for net platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Package Manager Console

PM > Install-Package Aspose.PDF

Printing PDF document via C#


You need Aspose.PDF for .NET to try the code in your environment.

  1. Load the PDF with an instance of Document.
  2. Get DocumentInfo using Document.Info property.
  3. Access & display different Document.Info properties.

Print PDF - C#

This sample code shows how to print PDF File

var inputFile = System.IO.Path.Combine(dataDir, "input.pdf");
var viewer = new Aspose.Pdf.Facades.PdfViewer();
viewer.BindPdf(inputFile);

viewer.AutoResize = true;
viewer.AutoRotate = true;
viewer.PrintPageDialog = false;

var ps = new Aspose.Pdf.Printing.PrinterSettings();
var pgs = new Aspose.Pdf.Printing.PageSettings();
var prtdoc = new System.Drawing.Printing.PrintDocument();

// Set printer name
ps.PrinterName = prtdoc.PrinterSettings.PrinterName;

// Set PageSize (if required)
pgs.PaperSize = Aspose.Pdf.Printing.PaperSizes.A4;

// Set PageMargins (if required)
pgs.Margins = new Aspose.Pdf.Devices.Margins(0, 0, 0, 0);

// Print document using printer and page settings
viewer.PrintDocumentWithSettings(pgs, ps);

// Close the PDF file after priting
viewer.Close();