How to Print PDF

Learn how easily print PDF documents with high quality using .NET PDF library

How to print PDF with .NET

To print a PDF file in .NET, we can utilize the Aspose.PDF for .NET API, which is a user-friendly and robust document manipulation API for the .NET platform. Simply open the NuGet package manager, search for Aspose.PDF, and install it. Alternatively, you can use the command below in the Package Manager Console.

Printing a PDF file, Aspose.PDF for .NET API can be utilized. This API is designed to provide a feature-rich, powerful, and user-friendly document manipulation experience for .NET. It can be easily installed using the NuGet package manager. Alternatively, you can use the command given below from the Package Manager Console.

PM > Install-Package Aspose.PDF

Print PDF

The code below is a C# code snippet that demonstrates how to print a PDF file programmatically using the Aspose.PDF for .NET API. The code first creates a PdfViewer object and binds the input PDF file to it. Then it sets some attributes for printing such as auto-resize, auto-rotate, and disables the page number dialog. Next, it creates objects for printer and page settings and PrintDocument. The printer settings include the printer name and paper size, while the page settings include margins. Finally, the code calls the PrintDocumentWithSettings method of the PdfViewer object to print the document using the specified printer and page settings. After printing, the PDF file is closed using the Close method of the PdfViewer object.

Use following code snippet for this:

    // Create PdfViewer object 
	PdfViewer viewer = new PdfViewer(); 
 
	// Open input PDF file 
	viewer.BindPdf(System.IO.Path.Combine(_dataDir, "input.pdf")); 
 
	// Set attributes for printing 
	viewer.AutoResize = true;     	// Print the file with adjusted size 
	viewer.AutoRotate = true;     	// Print the file with adjusted rotation 
	viewer.PrintPageDialog = false;   // Do not produce the page number dialog when printing 
 
	// Create objects for printer and page settings and PrintDocument 
	System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings(); 
	System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings(); 
	System.Drawing.Printing.PrintDocument prtdoc = new System.Drawing.Printing.PrintDocument(); 
 
	// Set printer name 
	ps.PrinterName = prtdoc.PrinterSettings.PrinterName; 
 
	// Set PageSize (if required) 
	pgs.PaperSize = new System.Drawing.Printing.PaperSize("A4", 827, 1169); 
 
	// Set PageMargins (if required) 
	pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0); 
 
	// Print document using printer and page settings 
	viewer.PrintDocumentWithSettings(pgs, ps); 
 
	// Close the PDF file after priting 
	viewer.Close();

How to print PDF documents

This code demonstrates how to print a PDF document using C# code with the help of Aspose.PDF for .NET API. The code uses the PdfViewer object to open the input PDF file and set various attributes for printing. It then creates objects for printer and page settings and PrintDocument. The code sets the printer name and paper size for the printer settings, while the page settings include margins. Finally, the code calls the PrintDocumentWithSettings method of the PdfViewer object to print the document using the specified printer and page settings. After printing, the Close method of the PdfViewer object is called to close the PDF file.

Documentation Aspose.PDF for .NET Library

See other features of Aspose.PDF for .NET library on Documentation pages

Get a Free License:

Get a temporary license and try print PDF feature with no limitations. Additionally, this article offers a detailed guide and sample .NET code on how to print PDF files using Aspose.PDF.

Conclusion

This article covers the specifics of printing PDF files using C# using the Aspose.PDF library for .NET. To evaluate the capabilities of the library, you can use a temporary license. By following these steps, users can easily print PDF files using C# with full control over printer and page settings. If you want more details about Aspose.PDF libraries - visit our landings pages