Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
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.
Print
method to print PDF document with default settingsPrinterName
property to target the specific printerPrinterResolution
class in C#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:
To silently print PDF documents, first we need the following components to be installed on the local computer.
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
Select the C# Console App and click on next
New Project Dialog Box
Now, type the name of your project, select the Location, and click next
Web Forms
Choose the latest .NET Framework for your application. We will use stable version 6.0.
Additional Information
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.
Right-click the project file in the Solution Explorer
Solution Explorer
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
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/")
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()
This Print
method will send the PDF to the default printer for printing.
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()
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
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()
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)
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
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.
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.
IronPrint is Iron Software's .NET printing library that offers compatibility across Windows, macOS, Android, and iOS.
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.
IronPDF allows creating, reading, and editing PDF documents, generating PDFs from HTML, and includes features like merging, splitting, and printing PDFs without Adobe Reader.
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.
Yes, you can specify a printer name using the PrinterSettings.PrinterName property when printing a PDF with IronPDF.
Yes, you can set a custom printer resolution using the DefaultPageSettings.PrinterResolution property.
The PrintToFile method allows you to print a PDF document directly to a specified file location without opening the printer dialog.
No, IronPDF does not require Adobe Acrobat Reader for viewing or editing PDF documents.
IronPDF is free for individual development and offers a free trial license for testing its full functionality. It can be licensed for commercial use.
Visual Studio is the recommended IDE for C# development with IronPDF, which can be downloaded from the Visual Studio website.