USING IRONPRINT

How to Print PDF Files in C# Silently

PDF document is a Portable Document Format which can store and transfer data in the requested format. It preserves the formatting of the data stored and allows its users to focus on other aspects of handling digital documents. Printing digital documents is a tedious task as data displays differently on different platforms. But sending data in PDF documents helps preserve the format for printing. However, printing PDF files programmatically can be a challenge for developers in C#. Thanks to IronPDF - C# PDF Library, it makes the process of printing PDF files extremely easy and hassle-free.

This article will explain how to silently print PDF documents in C# using the IronPDF Library.

IronPDF - C# PDF Library

IronPDF is a C# .NET Library, which allows developers to create, read, and edit PDF documents. It is a top notch C# Library and prioritizes accuracy, ease of use, and speed. It is specially designed for C#, F#, & VB.NET and highly compatible with .NET 7, 6, 5, Core, Standard, or Framework. It helps generate PDFs from HTML for Web, Desktop, and Console utilizing IronPDF's powerful Chromium engine.

Additionally, IronPDF allows the user to manipulate and edit PDFs, add headers and footers, extract text and images from PDFs with ease.

Some Important Features include:

  • Load and Generate PDF files from different file formats
  • Save and Print PDF files using Default printer
  • Merge and Splitting PDF file
  • PDF Editor without Adobe Reader

Steps to Silently Print PDF Documents in C# using IronPDF Library

To silently print PDF documents, first we need the following components to be installed on the local computer.

  1. Visual Studio - It is the official IDE for C# development and it must be installed on the computer. You can download and install from Visual Studio website.
  2. Create Project - To create a console application for PDF printing in C#, follow the steps using Visual Studio 2022:

    • Open Visual Studio and click on create a new project

      Visual Studio

      Visual Studio

    • Select the C# Console App and click on next

      New Project Dialog Box

      New Project Dialog Box

    • Now, type the name of your project, select the Location, and click next

      Web Forms

      Web Forms

    • Choose the latest .NET Framework for your application. We will use stable version 6.0.

      Additional Information

      Additional Information

    • Click on create, the console project is created and we are ready to print PDF documents programmatically.
  3. Install IronPDF - There are 3 ways to download and install the IronPDF library. These are as follows:

    • Using Visual Studio - Visual Studio has NuGet Package Manager which helps to install NuGet packages in C# projects.

      • Click on Tools in Menu bar, or
      • Right-click the project file in the Solution Explorer

        Solution Explorer

        Solution Explorer

         related to Steps to Silently Print PDF Documents in C# using IronPDF Library

        Project Menu > Manage NuGet Packages

      • Once it is opened, browse IronPDF in NuGet package manager and install it, as shown below:

        Install IronPDF from NuGet Package

        Install IronPDF from NuGet Package

    • Download the NuGet Package directly - Another way to download IronPDF is by navigating to the NuGet website and downloading the package directly. Here is the link https://www.nuget.org/packages/IronPdf/.
    • Download the IronPDF .DLL Library - IronPDF can also be downloaded directly from IronPDF website. Navigate to: IronPDF DLL download to install it. Reference the .DLL file in your project to use it.

Generate a PDF File and Print Job

Here we will generate a PDF file from a URL. Creating a PDF file is easy and usually a two-step process. The following code sample generates a PDF:

using IronPdf;

// Initialize a new instance of ChromePdfRenderer.
ChromePdfRenderer Renderer = new ChromePdfRenderer();

// Render the specified URL as a PDF document.
PdfDocument Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/");
using IronPdf;

// Initialize a new instance of ChromePdfRenderer.
ChromePdfRenderer Renderer = new ChromePdfRenderer();

// Render the specified URL as a PDF document.
PdfDocument Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/");
Imports IronPdf

' Initialize a new instance of ChromePdfRenderer.
Private Renderer As New ChromePdfRenderer()

' Render the specified URL as a PDF document.
Private Pdf As PdfDocument = Renderer.RenderUrlAsPdf("https://ironpdf.com/")
$vbLabelText   $csharpLabel

A PDF document object is created with the above code and it is ready for printing. Next, we will use the default printer to paper print PDF documents. The code is a one-liner and is as follows:

// Print the PDF document using the default printer settings.
Pdf.Print();
// Print the PDF document using the default printer settings.
Pdf.Print();
' Print the PDF document using the default printer settings.
Pdf.Print()
$vbLabelText   $csharpLabel

This Print method will send the PDF to the default printer for printing.

Advanced Printing Options

For silent printing, IronPDF provides various advanced printing options.

PdfDocument.GetPrintDocument method is used, and the result is stored in System.Drawing.Printing.PrintDocument object. The code is simple and as following:

// Remember to add assembly reference to System.Drawing.dll in project

// Get the print document for the PDF.
System.Drawing.Printing.PrintDocument PrintPDF = Pdf.GetPrintDocument();
// Remember to add assembly reference to System.Drawing.dll in project

// Get the print document for the PDF.
System.Drawing.Printing.PrintDocument PrintPDF = Pdf.GetPrintDocument();
' Remember to add assembly reference to System.Drawing.dll in project

' Get the print document for the PDF.
Dim PrintPDF As System.Drawing.Printing.PrintDocument = Pdf.GetPrintDocument()
$vbLabelText   $csharpLabel

Specify Printer Name

IronPDF also gives the opportunity to print to a specific printer. To specify the name, the PrinterSettings.PrinterName property is used. First, we need to get the current PDF document object. The code sample goes as follows:

using (var printDocument = pdfDocument.GetPrintDocument())
{
    // Specify the printer name.
    printDocument.PrinterSettings.PrinterName = "Microsoft Print to PDF";

    // Send the print job to the specified printer.
    printDocument.Print();
}
using (var printDocument = pdfDocument.GetPrintDocument())
{
    // Specify the printer name.
    printDocument.PrinterSettings.PrinterName = "Microsoft Print to PDF";

    // Send the print job to the specified printer.
    printDocument.Print();
}
Using printDocument = pdfDocument.GetPrintDocument()
	' Specify the printer name.
	printDocument.PrinterSettings.PrinterName = "Microsoft Print to PDF"

	' Send the print job to the specified printer.
	printDocument.Print()
End Using
$vbLabelText   $csharpLabel

Set Printer Resolution

Another cool feature is setting the printer resolution. We can control the number of pixels to be printed, displayed, depending on the output. The DefaultPageSettings.PrinterResolution property of the PDF document can be used to set the resolution. Here is a very quick code sample:

// Set the custom resolution for the printer.
printDocument.DefaultPageSettings.PrinterResolution = new PrinterResolution
{
    Kind = PrinterResolutionKind.Custom,
    X = 1200,
    Y = 1200
};

// Send the print job with the custom resolution settings.
printDocument.Print();
// Set the custom resolution for the printer.
printDocument.DefaultPageSettings.PrinterResolution = new PrinterResolution
{
    Kind = PrinterResolutionKind.Custom,
    X = 1200,
    Y = 1200
};

// Send the print job with the custom resolution settings.
printDocument.Print();
' Set the custom resolution for the printer.
printDocument.DefaultPageSettings.PrinterResolution = New PrinterResolution With {
	.Kind = PrinterResolutionKind.Custom,
	.X = 1200,
	.Y = 1200
}

' Send the print job with the custom resolution settings.
printDocument.Print()
$vbLabelText   $csharpLabel

PrintToFile Method

The PdfDocument class provides the PrintToFile method which allows us to print PDF to a file in C#. It takes the pathToFile as an argument to print the file directly to that location without opening the printer dialog. The code is simple and as follows:

// Print the document to a specified file location.
printDocument.PrintToFile("PathToFile", false);
// Print the document to a specified file location.
printDocument.PrintToFile("PathToFile", false);
' Print the document to a specified file location.
printDocument.PrintToFile("PathToFile", False)
$vbLabelText   $csharpLabel

The complete code example goes as follows:

using IronPdf;

// Initialize the PDF renderer and create the PDF document.
ChromePdfRenderer Renderer = new ChromePdfRenderer();
PdfDocument pdfDocument = Renderer.RenderUrlAsPdf("https://ironpdf.com/");

using (var printDocument = pdfDocument.GetPrintDocument())
{
    // Specify the printer name.
    printDocument.PrinterSettings.PrinterName = "Microsoft Print to PDF";

    // Set a custom print resolution.
    printDocument.DefaultPageSettings.PrinterResolution = new PrinterResolution
    {
        Kind = PrinterResolutionKind.Custom,
        X = 1200,
        Y = 1200
    };

    // Execute the print job.
    printDocument.Print();
}
using IronPdf;

// Initialize the PDF renderer and create the PDF document.
ChromePdfRenderer Renderer = new ChromePdfRenderer();
PdfDocument pdfDocument = Renderer.RenderUrlAsPdf("https://ironpdf.com/");

using (var printDocument = pdfDocument.GetPrintDocument())
{
    // Specify the printer name.
    printDocument.PrinterSettings.PrinterName = "Microsoft Print to PDF";

    // Set a custom print resolution.
    printDocument.DefaultPageSettings.PrinterResolution = new PrinterResolution
    {
        Kind = PrinterResolutionKind.Custom,
        X = 1200,
        Y = 1200
    };

    // Execute the print job.
    printDocument.Print();
}
Imports IronPdf

' Initialize the PDF renderer and create the PDF document.
Private Renderer As New ChromePdfRenderer()
Private pdfDocument As PdfDocument = Renderer.RenderUrlAsPdf("https://ironpdf.com/")

Using printDocument = pdfDocument.GetPrintDocument()
	' Specify the printer name.
	printDocument.PrinterSettings.PrinterName = "Microsoft Print to PDF"

	' Set a custom print resolution.
	printDocument.DefaultPageSettings.PrinterResolution = New PrinterResolution With {
		.Kind = PrinterResolutionKind.Custom,
		.X = 1200,
		.Y = 1200
	}

	' Execute the print job.
	printDocument.Print()
End Using
$vbLabelText   $csharpLabel

When the code is executed, it converts a URL to a PDF document. Then to silently print a PDF document, the GetPrintDocument method is used. On successful compiling and executing the program files, a printer dialog box appears to save it as a PDF document. The PDF is then saved using the specified printer name.

Csharp Print Pdf Silently 8 related to PrintToFile Method

Csharp Print Pdf Silently 9 related to PrintToFile Method

Summary

In this article, we closely looked at how to silently print a PDF document using IronPDF. IronPDF provides a lot of useful options while PDF printing. It can also keep track of printed pages and also allows you to print between the page range.

Silent printing along with other printing options makes IronPDF a standout Library in C# while working with PDFs.

IronPDF helps convert data from different formats to PDF and from PDF to different formats. It makes it easy for the developers to integrate PDF functionality in the application development process. Moreover, it does not require Adobe Acrobat Reader to view and edit PDF documents.

IronPDF is free for individual development and can be licensed for commercial use. It provides a free trial license to access and test out the full functionality of the library. You can check more details on this link.

Frequently Asked Questions

What is IronPrint?

IronPrint is Iron Software's .NET printing library that offers compatibility across Windows, macOS, Android, and iOS.

How can I silently print a PDF document in C# using IronPDF?

To silently print a PDF document in C#, you can utilize the IronPDF library's Print method with default settings or specify a printer using the PrinterName property.

What are the key features of IronPDF?

IronPDF allows creating, reading, and editing PDF documents, generating PDFs from HTML, and includes features like merging, splitting, and printing PDFs without Adobe Reader.

How do I install IronPDF in my C# project?

IronPDF can be installed via NuGet Package Manager in Visual Studio, by downloading from the NuGet website, or by downloading the IronPDF .DLL Library directly.

Can I specify a printer when printing a PDF with IronPDF?

Yes, you can specify a printer name using the PrinterSettings.PrinterName property when printing a PDF with IronPDF.

Is it possible to set a custom printer resolution with IronPDF?

Yes, you can set a custom printer resolution using the DefaultPageSettings.PrinterResolution property.

What is the PrintToFile method used for?

The PrintToFile method allows you to print a PDF document directly to a specified file location without opening the printer dialog.

Do I need Adobe Acrobat Reader to use IronPDF?

No, IronPDF does not require Adobe Acrobat Reader for viewing or editing PDF documents.

Is IronPDF free to use?

IronPDF is free for individual development and offers a free trial license for testing its full functionality. It can be licensed for commercial use.

What development environment is recommended for using IronPDF in C#?

Visual Studio is the recommended IDE for C# development with IronPDF, which can be downloaded from the Visual Studio website.

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.
< PREVIOUS
How to Print PDF File Without Dialog in C#
NEXT >
How to Print PDF Files in C# Without Using Adobe

Ready to get started? Version: 2025.6 just released

View Licenses >