How to Print PDF Files in C#

Sending a PDF to a printer from .NET C# code automates the printing process, allowing you to integrate printing functionality into your applications, reducing manual efforts, and ensuring consistency in PDF file production. It provides precise control over the printing process.

IronPDF offers the option to quickly print programmatically to a physical printer in one method call, allowing you to print multiple PDF files. The printer resolution can also be specified with configurable horizontal and vertical DPI. Use the method that accepts both Microsoft PrinterSettings and PrintController for further control over the PDF printing process.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPDF with NuGet

    PM > Install-Package IronPdf

  2. Copy the code

    IronPdf.PdfDocument.FromFile("input.pdf").Print();
  3. Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer


Get started with IronPDF

Start using IronPDF in your project today with a free trial.

First Step:
green arrow pointer


Print PDF File Example

The Print method is available through the PdfDocument object, allowing you to print both newly created and existing PDF files. By default, the method uses the system's default printer, but you can specify a different printer by passing its name as a string to the Print method.

Please noteAll printing features are only supported on Windows.

:path=/static-assets/pdf/content-code-examples/how-to/print-pdf-print.cs
using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Test printing</h1>");

// Send the document to "Microsoft Print to PDF" printer
pdf.Print("Microsoft Print to PDF");
Imports IronPdf

Private renderer As New ChromePdfRenderer()

Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Test printing</h1>")

' Send the document to "Microsoft Print to PDF" printer
pdf.Print("Microsoft Print to PDF")
$vbLabelText   $csharpLabel
Print queue

Printer Resolution

You can specify the resolution of the printed PDF by providing the desired DPI value to the Print method, which will apply the same DPI for both horizontal and vertical dimensions. To use different DPI values, pass two parameters to the method: the first for horizontal (x) DPI and the second for vertical (y) DPI.

:path=/static-assets/pdf/content-code-examples/how-to/print-pdf-dpi.cs
using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Test printing</h1>");

// Set custom DPI
pdf.Print(300);

// Specify printing resolution
pdf.Print(10, 10, "Microsoft Print to PDF");
Imports IronPdf

Private renderer As New ChromePdfRenderer()

Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Test printing</h1>")

' Set custom DPI
pdf.Print(300)

' Specify printing resolution
pdf.Print(10, 10, "Microsoft Print to PDF")
$vbLabelText   $csharpLabel

Let's see how to rasterize and print a PDF file in the next example.


Print to File

The PrintToFile method efficiently rasterizes PDF documents by converting them into bitmap (pixel-based) images and saving them as a PDF file. This process is handled by the Windows built-in printer, such as "Microsoft Print to PDF." Notably, this method saves the PDF to disk without sending it to a physical printer.

:path=/static-assets/pdf/content-code-examples/how-to/print-pdf-print-to-file.cs
using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Test printing</h1>");

// Print to file
pdf.PrintToFile("");
Imports IronPdf

Private renderer As New ChromePdfRenderer()

Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Test printing</h1>")

' Print to file
pdf.PrintToFile("")
$vbLabelText   $csharpLabel

Explore Print PDF Document Settings

To customize printing options, use the GetPrintDocument method, which accepts Microsoft PrinterSettings and PrintController objects. This method returns the current print document object. The PrinterSettings allows you to configure options such as page range and printer selection, while PrintController enables control over the printing process, including handling exceptions, progress reporting, print dialogs, print previews, and other related tasks. Detailed descriptions of PrinterSettings options are provided below the code example.

:path=/static-assets/pdf/content-code-examples/how-to/print-pdf-printer-setting.cs
using IronPdf;
using System.Drawing.Printing;

ChromePdfRenderer renderer = new ChromePdfRenderer();

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Testing</h1>");

PrinterSettings settings = new PrinterSettings() {
    PrinterName = "Microsoft Print to PDF",

    // Number of Copy
    Copies = 2,

    // Page range to print
    FromPage = 2,
    ToPage = 4,
};

PrintDocument document = pdf.GetPrintDocument(settings);

// Print
document.Print();
Imports IronPdf
Imports System.Drawing.Printing

Private renderer As New ChromePdfRenderer()

Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Testing</h1>")

Private settings As New PrinterSettings() With {
	.PrinterName = "Microsoft Print to PDF",
	.Copies = 2,
	.FromPage = 2,
	.ToPage = 4
}

Private document As PrintDocument = pdf.GetPrintDocument(settings)

' Print
document.Print()
$vbLabelText   $csharpLabel
  • CanDuplex: Indicates whether the printer supports duplex (double-sided) printing. If true, printing on both sides of the paper is possible; otherwise, it cannot.
  • Collate: Specifies whether multiple PDF files or copies of a PDF document should be collated (organized in order) when printed. When true, the printer collates the copies; when false, it does not.
  • Copies: Sets the number of copies of the PDF document to print. It determines how many identical copies of the document will be printed.
  • DefaultPageSettings: Represents the default page settings for the printer, including paper size, margins, and orientation.
  • Duplex: Specifies the duplex (double-sided) printing mode to use. Options include Duplex.Default, Duplex.Simplex (single-sided), Duplex.Horizontal, and Duplex.Vertical.
  • InstalledPrinters: Provides a collection of installed printer names on the system. You can iterate through this collection to get the names of available printers.
  • IsDefaultPrinter: Indicates whether the printer specified in PrinterName is set as the default printer on the system.
  • IsPlotter: Determines whether the printer is a plotter. Plotter printers are often used for large-format printing, such as for architectural or engineering drawings.
  • IsValid: Indicates whether the printer settings are valid and can be used for printing PDF files.
  • LandscapeAngle: Specifies the angle (rotation) of landscape orientation for the printer, usually 90 degrees for portrait.
  • MaximumCopies: Represents the maximum number of copies that can be specified for printing PDF.
  • MaximumPage: Specifies the maximum page number that can be set for printing or conversion.
  • MinimumPage: Specifies the minimum page number that can be set for printing or conversion.
  • PaperSizes: Provides a collection of supported paper sizes for the printer. You can query this collection to determine available paper sizes.
  • PaperSources: Offers a collection of paper sources or trays available for the printer. This can be useful when selecting the paper source for printing PDF files.
  • PrinterName: Specifies the name of the printer to use for printing or conversion.
  • PrinterResolutions: Provides a collection of available printer resolutions, allowing you to choose the print quality.
  • PrintFileName: Gets or sets the file name when printing to a file using PrintToFile.
  • PrintRange: Specifies the range of PDF pages to print, such as all pages, a specific range, or a selection. Use this to print specific pages.
  • FromPage: Specifies the starting page number for printing or conversion. Printing will begin from this page.
  • ToPage: Specifies the ending page number for printing or conversion. Printing will stop after reaching this page.
  • PrintToFile: Indicates whether to print to a file instead of a physical printer. When true, you can specify the file path using PrintFileName.
  • SupportsColor: Indicates whether the printer supports color printing. If true, print in color is supported; otherwise, it is limited to black and white (monochrome) printing.

Lastly, to configure the default printer to print PDFs, you may go to the "Printers & Scanners" section of the machine settings.

Frequently Asked Questions

What is the best way to print PDF documents using .NET C#?

The best way to print PDF documents using .NET C# is by utilizing the IronPDF library. It provides a simple `Print` method that allows you to send PDF files directly to a physical printer.

How can I install the IronPDF library in my .NET project?

You can install the IronPDF library in your .NET project using the NuGet Package Manager in Visual Studio. Search for 'IronPDF' in the NuGet package manager and add it to your project.

Can I customize the print settings for a PDF document?

Yes, with IronPDF, you can customize print settings using the `GetPrintDocument` method, which allows you to specify options such as printer selection, page range, and duplex printing.

Is it possible to print specific pages from a PDF file?

Yes, you can print specific pages from a PDF file by setting the `PrintRange`, `FromPage`, and `ToPage` properties within the `PrinterSettings` object in IronPDF.

How do I print a PDF with high-quality settings?

To print a PDF with high-quality settings using IronPDF, you can configure the DPI (dots per inch) by specifying the desired DPI values in the `Print` method to ensure high-resolution output.

Can I print PDF files on non-Windows platforms?

Currently, IronPDF's printing features are supported primarily on Windows platforms. However, the library is versatile and can be used for other functionalities on macOS, Android, and iOS.

How do I save a PDF document as an image file?

You can save a PDF document as an image file using the `PrintToFile` method in IronPDF, which converts the PDF into bitmap images and saves them to disk.

Does IronPDF support duplex printing for PDF documents?

Yes, IronPDF supports duplex or double-sided printing if your printer has this capability. This can be configured through the `PrinterSettings` object.

How can I print multiple copies of a PDF using IronPDF?

You can print multiple copies of a PDF by setting the `Copies` property in the `PrinterSettings` object in IronPDF to the desired number of copies.

What should I do if my PDF does not print correctly?

If your PDF does not print correctly, ensure that you have the latest version of IronPDF installed and check the printer settings in your application. Verify that the correct printer is selected, and review any error messages for further troubleshooting.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.
Reviewed by
Jeff Fritz
Jeffrey T. Fritz
Principal Program Manager - .NET Community Team
Jeff is also a Principal Program Manager for the .NET and Visual Studio teams. He is the executive producer of the .NET Conf virtual conference series and hosts 'Fritz and Friends' a live stream for developers that airs twice weekly where he talks tech and writes code together with viewers. Jeff writes workshops, presentations, and plans content for the largest Microsoft developer events including Microsoft Build, Microsoft Ignite, .NET Conf, and the Microsoft MVP Summit