PM > Install-Package XDoc.PDF

How to Start Tutorials Troubleshooting Main Operations Convert PDF Read PDF Edit PDF PDF Report Generator Work with PDF Modules PDF Document PDF Pages Text Image Graph & Path Annotation, Markup & Drawing Redaction Security Digital Signature Forms Watermark Bookmark Link File Attachment File Metadata Printing Work with Other SDKs Barcode read Barcode create OCR Twain

C# PDF Print Library
How to send, print Adobe pdf file to printer without Acrobat Reader installed using C# .net


.NET PDF Document Printer API SDK for Visual C# .NET Class Applications





In this tutorial, you learn how to print PDF programmatically using C#

  • Select a specific printer or use default printer
  • Print a PDF document or PDF stream object
  • Choose printing PDF pages range
  • Choose printing resolution
  • No need to install Adobe Reader
  • Easy to enable printing function in ASP.NET MVC, Windows Forms application using C#

How to print a PDF file programmatically using C#

  1. Download XDoc.PDF Printer C# library
  2. Install C# library to print Adobe PDF file programmatically
  3. Step by Step Tutorial


























  • A best PDF printer control for Visual Studio .NET and compatible with C# programming language
  • Quicken PDF printer library allows C# users to batch print PDF file in .NET framework
  • Free library control SDK for automatically printing PDF document online in ASP.NET WebForm application
  • Standalone and easy-to-use API allows C# developers to send a source PDF document file to an actual physical printer device
  • Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint
  • C# source code for printing PDF adobe PDF file in .NET Windows Forms project
  • Provide variety of printing options, like like number of copies, PDF document printing orientation, PDF document printing paper size and PDF document printing resolution
  • Fully-featured PDF document printing SDK can help to easily create a custom web-based client-server printing application or a custom Windows Forms project




How to print a PDF file to a specific printer using C#


The following steps show how to print a PDF document to a selected printer.

  1. Create a PDFPrinterOption object with the specified printer name
  2. Print a PDF file by calling Print method of the class PDFPrinter


String inputFilePath = @"C:\demo_1.pdf";
PDFPrinterOption op = new PDFPrinterOption();
//  Set printer name for printing
op.PrinterName = "Selected printer name";
PDFPrinter.Print(inputFilePath, new PDFPrintSetting(), op);






About printing options


You can apply the following options to choose printing pages range and output resolutions in class PDFPrintSetting.



  • StartPageIndex: Index of the first page to print. Default: 0
  • StopPageIndex: Index of the last page to print. -1 means to print all remained pages from the first one. Default: -1
  • PageResolution: Conversion resolution for the page (in pixel per inch). Default: 300 (dpi)






How to choose printing PDF pages range using C#


The following C# source code shows how to choose a range of PDF pages to print



String inputFilePath = Program.RootPath + "\\" + "1.pdf";
//  print a range of pages from page index 1 to 2
PDFPrintSetting setting = new PDFPrintSetting();
setting.StartPageIndex = 1;
setting.StopPageIndex = 2;
PDFPrinter.Print(inputFilePath, setting, new PDFPrinterOption());






How to change the resolution of the PDF printing output using C#


The following C# source code shows how to set the printing PDF pages resolution



String inputFilePath = Program.RootPath + "\\" + "1.pdf";
//  set print resolution to 600 dpi
PDFPrintSetting setting = new PDFPrintSetting();
setting.StartPageIndex = 1;
setting.StopPageIndex = 1;
setting.PageResolution = 600;
PDFPrinter.Print(inputFilePath, setting, new PDFPrinterOption());






How to print PDF from byte array using C#


The following C# source code shows how to print PDF from byte array object



String inputFilePath = @"C:\demo_1.pdf";
byte[] dataBytes = File.ReadAllBytes(inputFilePath);
PDFPrinterOption op = new PDFPrinterOption();
//  Set printer name for printing
op.PrinterName = "Microsoft Print to PDF";
PDFPrinter.Print(dataBytes, new PDFPrintSetting(), op);






How to print PDF from file stream object using C#


The following C# source code shows how to print PDF from a FileStream object in .net application



String inputFilePath = @"C:\demo_1.pdf";
using (FileStream fs = File.Open(inputFilePath, FileMode.Open, FileAccess.Read))
{
    PDFPrinterOption op = new PDFPrinterOption();
    //  Set printer name for printing
    op.PrinterName = "Microsoft Print to PDF";
    PDFPrinter.Print(fs, new PDFPrintSetting(), op);
}






How to print PDF from PDFDocument object using C#


The following C# source code shows how to print PDF from PDFDocument object in .net application



String inputFilePath = @"C:\demo_1.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);
//  Save PDFDocument object to data bytes
byte[] dataBytes = doc.SaveToBytes();
PDFPrinterOption op = new PDFPrinterOption();
//  Set printer name for printing
op.PrinterName = "Microsoft Print to PDF";
PDFPrinter.Print(dataBytes, new PDFPrintSetting(), op);








Common Asked Questions

How do I get a PDF to print?

You can send a PDF document to print using free Acrobar reader application or other free PDF reader software on Windows or Mac. If you want to build a web or desktop app to enable PDF file printing function, you quickly enable PDF whole document printing, specified PDF pages printing using C# PDF library.

How to enable PDF for printing?

In the PDF document, you need grant the document printing permission. You can enable PDF file print using Acrobar Pro, or other PDF editor software. You can also use RasterEdge XDoc.PDF C# library to enable PDF document printing with few lines of C# codes in your C# apps.

Why can't I print a PDF file?

There are several possible reasons why you can print a PDF file.
  1. Printer out of work
  2. Network issue. It cannot connect to the printer.
  3. PDF document permission. The PDF file owner does not allow for printing.
If it is the last reason, you can use C# PDF sdk library to enable the PDF document printing permission, and send it to the printer directly in C# ASP.NET Core, MVC, WinForms, WPF, web and desktop apps.

Do I need an Adobe Reader to print PDF files?

Besides Adobe Reader, you can also use other free PDF reader, such as Foxit PDF Reader. If you know C# programming, you can also use XDoc.PDF C# PDF library free trial version to print PDF files without any cost.