USING IRONPRINT

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

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.

Csharp Print Pdf Files 2 related to Install NuGet Package

NuGet Package Manager Console will open as shown below:

NuGet Package Manager Console

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

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
$vbLabelText   $csharpLabel

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
$vbLabelText   $csharpLabel

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
$vbLabelText   $csharpLabel
  • The Print() function will print the loaded file using your default printer.

Test the Program

Press Ctrl + F5 to run the program.

Console

Console


Print Multiple PDF Documents in C#

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

14 PDF files

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
$vbLabelText   $csharpLabel

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

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
$vbLabelText   $csharpLabel

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

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
$vbLabelText   $csharpLabel

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.

Csharp Print Pdf Files 10 related to Run the Program:

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

Csharp Print Pdf Files 11 related to Run the Program:

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

Csharp Print Pdf Files 12 related to Run the Program:

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

What is IronPDF?

IronPDF is a .NET Library that provides a simple way to read, create, manipulate, and print PDF files. It works with C# and VB .NET applications and is compatible with ASP .NET, ASP .NET core, MVC, Web Forms, and Web APIs on .NET and .NET core.

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

To print a PDF file using IronPDF in C#, you need to load the PDF document from a file using PdfDocument.FromFile method and then call the Print method on the loaded document.

Can I print multiple PDF files at once with IronPDF?

Yes, you can print multiple PDF files at once by iterating through an array or list of file paths and calling the Print method for each file using IronPDF.

How do I convert a URL to a PDF and print it using IronPDF?

To convert a URL to a PDF and print it using IronPDF, use the HtmlToPdf.RenderUrlAsPdf method to create a PDF from the URL, and then call the Print method on the resulting PDF document.

Is it possible to specify a different printer when printing a PDF using IronPDF?

Yes, you can specify a different printer by setting the PrinterName property of the PrinterSettings object in the GetPrintDocument method of the PdfDocument class.

What are the system requirements for using IronPDF?

IronPDF can be used with .NET Framework, .NET Core, and .NET 5 and 6 applications. It is compatible with Windows, macOS, Android, and iOS platforms.

Where can I find more information about getting started with IronPrint?

You can find more information about getting started with IronPrint by visiting the documentation provided by Iron Software at their website.

What are the advantages of using PDF files?

PDF files are lightweight, supported by most operating systems, easily shared between devices, and maintain consistent formatting across different platforms, making them ideal for document sharing.

Do I need to have knowledge of C# to use IronPDF?

Yes, having a basic knowledge of C# programming is helpful for understanding and implementing the examples and functionalities of IronPDF.

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 Files in .NET Core

Ready to get started? Version: 2025.6 just released

View Licenses >