C# Print PDF Files using IronPDF
PDF is the most commonly used file format. It is lightweight and supported by most operating systems. PDF files can be shared easily from one device to another. They provide ease of reading as they appear exactly the same on any interface and OS. PDFs can be accessed from all devices including mobiles, tablets, etc.
Their popularity demands that all C# developers know how to print PDF files using C#. This is because you might come across a problem when you have to print a document such as an invoice, pay slip, order slip or profile, etc. These documents are often in PDF file format, so we must know how to print PDF files using C#.
Printing PDF documents in C# can be done using multiple libraries. But, one issue you may come across is the license fee. Most of them are not free or are difficult to use. But luckily, you do not have to worry. I have found the easiest and simplest way to print PDF files in C#.
I will use the IronPDF Library to print PDF documents. Believe me, you are going to like it!
What will you get from this article?
After reading this article you will be able to perform the following tasks:
- Print single PDF documents in C#
- Print multiple PDF files in one go using C#
- Convert a URL to PDF and then print it.
You must have basic knowledge of C# programming for a better understanding of this tutorial.
Before starting the tutorial, let's first understand what IronPDF is.
IronPDF:
IronPDF is a .NET Library that provides us the simplest way to read, create, manipulate and print PDF files. This library can be used in C# and VB .NET applications. It works easily with ASP .NET, ASP .NET core, MVC, Web Forms, and Web APIs on both .NET and .NET core. It allows users to download PDF files, send them by email and store them in a cloud.
You can explore more about IronPDF using this link.
Let's start the demonstration.
Open Visual Studio
Open Visual Studio. Create a new project or open an existing project if you are going to add this functionality to your existing software.
I am using Console Application for this tutorial; you can use any of your choices according to your software requirements.

Project Created.
Install NuGet Package
Open the console by clicking on Tools > NuGet Package Manager > Package Manager Console from the Menu bar on the top of the window.

NuGet Package Manager Console will open as shown below:

NuGet Package Manager Console
Write the following command in the console to Install IronPdf NuGet Package and press Enter.
Install-Package IronPrint
NuGet Package will be installed as shown below:

Install NuGet Package
Print PDF Filed in C#
Now, let us consider an example to demonstrate how we can print a PDF file in C# using the IronPDF Library.
Open Program.cs
file. Add the following namespace at the top of the Program.cs
file to use IronPDF:
using IronPdf;
using IronPdf;
Imports IronPdf
Now, write the following code inside the Main
function:
using System; // Required for Console operations
class Program
{
static void Main()
{
// Load the PDF document from file
using PdfDocument pdfDocument = PdfDocument.FromFile(@"D:\Sample.pdf");
// Print the loaded PDF document to the default printer
pdfDocument.Print();
// Print operation success message to console
Console.WriteLine("File Printed Successfully!");
Console.ReadKey();
}
}
using System; // Required for Console operations
class Program
{
static void Main()
{
// Load the PDF document from file
using PdfDocument pdfDocument = PdfDocument.FromFile(@"D:\Sample.pdf");
// Print the loaded PDF document to the default printer
pdfDocument.Print();
// Print operation success message to console
Console.WriteLine("File Printed Successfully!");
Console.ReadKey();
}
}
Imports System ' Required for Console operations
Friend Class Program
Shared Sub Main()
' Load the PDF document from file
Using pdfDocument As PdfDocument = PdfDocument.FromFile("D:\Sample.pdf")
' Print the loaded PDF document to the default printer
pdfDocument.Print()
' Print operation success message to console
Console.WriteLine("File Printed Successfully!")
Console.ReadKey()
End Using
End Sub
End Class
Let's understand the code.
- The following line of code will load the PDF file into memory. "Sample.Pdf" is the file name and D Drive is my file location. You have to write a complete file path along with the file name.
using PdfDocument pdfDocument = PdfDocument.FromFile(@"D:\Sample.pdf");
using PdfDocument pdfDocument = PdfDocument.FromFile(@"D:\Sample.pdf");
Using pdfDocument As PdfDocument = PdfDocument.FromFile("D:\Sample.pdf")
End Using
- The
Print()
function will print the loaded file using your default printer.
Test the Program
Press Ctrl + F5 to run the program.

Console
Print Multiple PDF Documents in C#
I will show you how to print multiple PDF documents in C# using IronPDF.

14 PDF files
In this example, I have 14 PDF documents which I need to print. I have named them as numbers 1 - 14. You can save all your files with an ID, or you can save the file location in a database. Extract the file Path and Filename from the database, and save them in an array or on a list. Iterate that array or list and get all your files printed.
Write the following code inside the Main
function:
using System; // Required for Console operations
class Program
{
static void Main()
{
// Loop through each file number and print
for (int i = 1; i <= 14; i++)
{
// Load each PDF document from file
using PdfDocument pdfDocument = PdfDocument.FromFile($@"D:\Print\{i}.pdf");
// Inform which file is being printed
Console.WriteLine("Printing File: {0}.pdf", i);
// Print the loaded PDF document to the default printer
pdfDocument.Print();
// Print operation success message to console
Console.WriteLine("{0}.pdf Printed Successfully!", i);
}
Console.ReadKey();
}
}
using System; // Required for Console operations
class Program
{
static void Main()
{
// Loop through each file number and print
for (int i = 1; i <= 14; i++)
{
// Load each PDF document from file
using PdfDocument pdfDocument = PdfDocument.FromFile($@"D:\Print\{i}.pdf");
// Inform which file is being printed
Console.WriteLine("Printing File: {0}.pdf", i);
// Print the loaded PDF document to the default printer
pdfDocument.Print();
// Print operation success message to console
Console.WriteLine("{0}.pdf Printed Successfully!", i);
}
Console.ReadKey();
}
}
Imports System ' Required for Console operations
Friend Class Program
Shared Sub Main()
' Loop through each file number and print
For i As Integer = 1 To 14
' Load each PDF document from file
Using pdfDocument As PdfDocument = PdfDocument.FromFile($"D:\Print\{i}.pdf")
' Inform which file is being printed
Console.WriteLine("Printing File: {0}.pdf", i)
' Print the loaded PDF document to the default printer
pdfDocument.Print()
' Print operation success message to console
Console.WriteLine("{0}.pdf Printed Successfully!", i)
End Using
Next i
Console.ReadKey()
End Sub
End Class
I have used a for loop to generate Numbers from 1 to 14 according to my file name.
Run the Solution:
Press Ctrl + F5 to run the program.

Console
Convert URL to PDF then Print it:
I will show you how to print a web page by parsing URLs to IronPDF. The library will create a PDF file by parsing HTML. We can print that PDF document using the print function. Let's consider an example.
Write the following code inside the main function:
using System; // Required for Console operations
class Program
{
static void Main()
{
// HTML to PDF Renderer
IronPdf.HtmlToPdf Renderer = new IronPdf.HtmlToPdf();
// Inform about the printing operation
Console.WriteLine("Printing File");
// Render URL as PDF
using PdfDocument PdfDocument = Renderer.RenderUrlAsPdf("https://ironpdf.com/how-to/print-pdf/#advanced-printing");
// Print the PDF document
PdfDocument.Print();
// Print operation success message to console
Console.WriteLine("File Printed Successfully!");
}
}
using System; // Required for Console operations
class Program
{
static void Main()
{
// HTML to PDF Renderer
IronPdf.HtmlToPdf Renderer = new IronPdf.HtmlToPdf();
// Inform about the printing operation
Console.WriteLine("Printing File");
// Render URL as PDF
using PdfDocument PdfDocument = Renderer.RenderUrlAsPdf("https://ironpdf.com/how-to/print-pdf/#advanced-printing");
// Print the PDF document
PdfDocument.Print();
// Print operation success message to console
Console.WriteLine("File Printed Successfully!");
}
}
Imports System ' Required for Console operations
Friend Class Program
Shared Sub Main()
' HTML to PDF Renderer
Dim Renderer As New IronPdf.HtmlToPdf()
' Inform about the printing operation
Console.WriteLine("Printing File")
' Render URL as PDF
Using PdfDocument As PdfDocument = Renderer.RenderUrlAsPdf("https://ironpdf.com/how-to/print-pdf/#advanced-printing")
' Print the PDF document
PdfDocument.Print()
' Print operation success message to console
Console.WriteLine("File Printed Successfully!")
End Using
End Sub
End Class
This program will parse https://ironpdf.com/how-to/print-pdf/#advanced-printing
to PDF and the Print()
function will print the PDF using the default printer.
Let's run the program.
Run the Program:
Press Ctrl + F5 to run the solution.

Output displayed on screen
The Print()
function will print the document using the default printer. There may be a situation where we do not want to use the default printer. In that case, IronPDF provides us with one line code to change the printer name.
Change Printer Name:
Let's use an example to help us understand further. Use the following code to change the default printer:
using System; // Required for Console operations
class Program
{
static void Main()
{
// Load the PDF document from file
PdfDocument pdfDocument = PdfDocument.FromFile(@"D:\Sample.pdf");
// Change to a different printer by name
pdfDocument.GetPrintDocument().PrinterSettings.PrinterName = "Microsoft Print to PDF";
// Print the PDF document
pdfDocument.Print();
// Print operation success message to console
Console.WriteLine("File Printed Successfully!");
}
}
using System; // Required for Console operations
class Program
{
static void Main()
{
// Load the PDF document from file
PdfDocument pdfDocument = PdfDocument.FromFile(@"D:\Sample.pdf");
// Change to a different printer by name
pdfDocument.GetPrintDocument().PrinterSettings.PrinterName = "Microsoft Print to PDF";
// Print the PDF document
pdfDocument.Print();
// Print operation success message to console
Console.WriteLine("File Printed Successfully!");
}
}
Imports System ' Required for Console operations
Friend Class Program
Shared Sub Main()
' Load the PDF document from file
Dim pdfDocument As PdfDocument = PdfDocument.FromFile("D:\Sample.pdf")
' Change to a different printer by name
pdfDocument.GetPrintDocument().PrinterSettings.PrinterName = "Microsoft Print to PDF"
' Print the PDF document
pdfDocument.Print()
' Print operation success message to console
Console.WriteLine("File Printed Successfully!")
End Sub
End Class
You can see that I have added only one line of additional code to specify the printer. I have specified Microsoft Print to PDF for demonstration.
Run the Program:
Run the Program by pressing Ctrl + F5.
The following Dialogue Box will appear that will ask us to enter a file name to save because we are using Microsoft Print to PDF.

Specify the File name and click on the Save button. I have specified "SamplePrint.Pdf". The following console output will display:

Microsoft Print to PDF has printed a PDF file in my D Drive. Let's see it.

I hope this tutorial was helpful, interactive, and easy for you to understand. You can ask questions or give feedback on this tutorial in the comments section below.
Frequently Asked Questions
How do I print a PDF file in C# using IronPDF?
To print a PDF file using IronPDF in C#, load the PDF document with the PdfDocument.FromFile
method and then call the Print
method on the loaded document.
Can IronPDF be used to print multiple PDF files sequentially?
Yes, IronPDF can print multiple PDF files by iterating through a collection of file paths and invoking the Print
method for each document.
How can I convert a URL to a PDF and then print it in C#?
Using IronPDF, convert a URL to a PDF with the HtmlToPdf.RenderUrlAsPdf
method. Then, use the Print
method on the generated PDF document to print it.
Is it possible to select a specific printer for printing PDFs with IronPDF?
Yes, you can select a specific printer by setting the PrinterName
property within the PrinterSettings
object when using the GetPrintDocument
method of the PdfDocument
class.
What platforms does IronPDF support for PDF printing?
IronPDF supports PDF printing on .NET Framework, .NET Core, and .NET 5 and 6 applications, and it is compatible with Windows, macOS, Android, and iOS platforms.
How can I get started with printing PDFs in C# using a .NET library?
To get started with printing PDFs using IronPDF, install the library via the NuGet Package Manager in Visual Studio and follow the documentation and examples provided by Iron Software.
What are the benefits of using PDFs for document sharing?
PDFs are advantageous for document sharing as they are lightweight, maintain consistent formatting across different devices, and are supported by most operating systems.
Do I need advanced C# skills to use IronPDF for printing?
Basic knowledge of C# is sufficient to use IronPDF for printing tasks, as the library provides straightforward methods and examples to assist developers.