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
Printing PDF documents using C# is a common requirement in many desktop and web applications. The ability to generate and print PDFs programmatically provides developers with greater flexibility in handling document printing tasks. In C#, developers have access to a wide range of libraries and APIs that enable them to generate and print PDF documents with ease. Whether it's printing invoices, receipts, or reports, the ability to generate PDF documents dynamically and print them directly from the application saves time and effort. This article explores how to print PDFs using C# and some popular libraries and APIs available for this purpose.
For this purpose, we will use the following libraries and compare them.
In this article, we will see how you can print PDF files using IronPDF and ITextSharp. Both of these are advanced PDF manipulation APIs.
Print
method of the PrintHelper object in iTextSharpIronPDF is a powerful C# library that allows developers to create, manipulate, and process PDF documents with ease. It provides a wide range of features that make it a popular choice among developers, including the ability to convert HTML, CSS, and images to PDF, generate PDFs from scratch, and edit existing PDFs. IronPDF also supports a variety of document elements such as images, text, tables, and forms, and offers advanced functionalities such as digital signatures, watermarks, and encryption. Its user-friendly interface and comprehensive documentation make it a popular choice for .NET developers who want to integrate PDF functionality into their applications.
iText is a popular open-source PDF library used by developers to create, manipulate, and extract data from PDF documents in Java and .NET environments. iTextSharp was a .NET port from the original iText library before it was discontinued after the release of iText 5. iText 7 is the latest version of the library, and it is a complete rewrite of the original iText library, providing more features, better performance, and improved extensibility. iText 7 offers a range of functionalities, including PDF generation and manipulating PDF documents, digital signatures, form filling, and support creating PDFs. It is widely used in various industries, including finance, legal, and government, and it is known for its high-quality output and flexibility.
Here are the steps to install the IronPDF library using the NuGet Package Manager:
Right-click on the project in the Solution Explorer and select "Manage NuGet Packages".
Select "IronPdf" from the search results and click on the "Install" button.
That's it! You have successfully installed IronPDF using NuGet Package Manager. You can also download IronPDF directly from the IronPDF website or download the dll to manually install instead.
Here are the steps to install iTextsharp with NuGet Package Manager:
Right-click on the project in the Solution Explorer and select "Manage NuGet Packages".
Select "iText 7" from the search results and click on the "Install" button.
That's it! You have successfully installed iTextsharp using the NuGet Package Manager.
Printing PDFs is quite easy using IronPDF, and it provides many options to print a PDF file with just a few lines of code. Below, we will discuss a code example of printing the IronPDF tiger wiki page and sending instructions to the default printer using only IronPDF's render PDF object, without any other library.
using IronPdf;
// Initialize ChromePdfRenderer to render a URL as PDF
var renderer = new ChromePdfRenderer();
// Render the PDF from a URL
PdfDocument pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
// Print the PDF at 300 DPI to the default printer
pdf.Print(300, true);
// Get a PrintDocument for additional customization if needed
System.Drawing.Printing.PrintDocument printDocYouCanWorkWith = pdf.GetPrintDocument();
using IronPdf;
// Initialize ChromePdfRenderer to render a URL as PDF
var renderer = new ChromePdfRenderer();
// Render the PDF from a URL
PdfDocument pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
// Print the PDF at 300 DPI to the default printer
pdf.Print(300, true);
// Get a PrintDocument for additional customization if needed
System.Drawing.Printing.PrintDocument printDocYouCanWorkWith = pdf.GetPrintDocument();
Imports IronPdf
' Initialize ChromePdfRenderer to render a URL as PDF
Private renderer = New ChromePdfRenderer()
' Render the PDF from a URL
Private pdf As PdfDocument = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf")
' Print the PDF at 300 DPI to the default printer
pdf.Print(300, True)
' Get a PrintDocument for additional customization if needed
Dim printDocYouCanWorkWith As System.Drawing.Printing.PrintDocument = pdf.GetPrintDocument()
The above code demonstrates how to obtain data from a URL that IronPDF uses to create a PDF file. Then, the code sets the printer parameters and sends the PDF file to the default printer to print the PDF document directly.
Creating PDF documents using iTextSharp is quite easy, but when it comes to printing PDF files, it requires the help of other 3rd party libraries.
using iText.Kernel.Pdf;
using System.Drawing.Printing;
// Method to print a PDF using iTextSharp and another library (e.g., PrintDocument)
public void PrintPDF(string filePath) {
// Create a PdfReader to read the PDF file
PdfReader reader = new PdfReader(filePath);
// Create a PdfDocument to interact with the PDF data
PdfDocument pdfDoc = new PdfDocument(reader);
// Assuming there exists a PrintHelper class that can handle PDF printing
PrintHelper printHelper = new PrintHelper(pdfDoc);
// Print the PDF document using the helper
printHelper.Print();
// Close the PdfDocument to release resources
pdfDoc.Close();
}
using iText.Kernel.Pdf;
using System.Drawing.Printing;
// Method to print a PDF using iTextSharp and another library (e.g., PrintDocument)
public void PrintPDF(string filePath) {
// Create a PdfReader to read the PDF file
PdfReader reader = new PdfReader(filePath);
// Create a PdfDocument to interact with the PDF data
PdfDocument pdfDoc = new PdfDocument(reader);
// Assuming there exists a PrintHelper class that can handle PDF printing
PrintHelper printHelper = new PrintHelper(pdfDoc);
// Print the PDF document using the helper
printHelper.Print();
// Close the PdfDocument to release resources
pdfDoc.Close();
}
Imports iText.Kernel.Pdf
Imports System.Drawing.Printing
' Method to print a PDF using iTextSharp and another library (e.g., PrintDocument)
Public Sub PrintPDF(ByVal filePath As String)
' Create a PdfReader to read the PDF file
Dim reader As New PdfReader(filePath)
' Create a PdfDocument to interact with the PDF data
Dim pdfDoc As New PdfDocument(reader)
' Assuming there exists a PrintHelper class that can handle PDF printing
Dim printHelper As New PrintHelper(pdfDoc)
' Print the PDF document using the helper
printHelper.Print()
' Close the PdfDocument to release resources
pdfDoc.Close()
End Sub
The above code retrieves a PDF file from a path, creates a new PDF document object, and then uses a helper class to print the document by sending it to the default printer. Note that iTextSharp does not natively support printing, so an additional third-party library or code is required to handle the actual print job process.
Printing PDF documents using C# is an essential feature for many desktop and web applications. IronPDF and iTextSharp are two popular libraries used to create, manipulate, and print PDF documents with ease. Both libraries provide a range of functionalities, including converting HTML, CSS, and images to PDF, editing existing PDFs, and adding digital signatures, watermarks, and encryption. IronPDF is known for its user-friendly interface and comprehensive documentation, making it a popular choice for .NET developers. On the other hand, iTextSharp also offers a lot of PDF functionalities. Notably, however, it does not provide PDF printing functionality. To achieve this, we will have to use other third-party tools.
To learn more about printing PDFs using IronPDF, please visit the following link.
For a full comparison between IronPDF and iTextSharp, please visit this link.
IronPrint is Iron Software's .NET printing library offering compatibility across various platforms including Windows, macOS, Android, and iOS.
To print a PDF using iTextSharp, you need to download the library, load a PDF document using PdfReader, and then use a PrintHelper object to invoke the print method.
IronPDF offers features such as converting HTML, CSS, and images to PDF, generating PDFs from scratch, editing existing PDFs, and supporting document elements like images, text, tables, and forms. It also includes functionalities like digital signatures, watermarks, and encryption.
iTextSharp is a popular open-source PDF library for .NET environments, originally a port of the Java iText library, used for creating, manipulating, and extracting data from PDF documents.
To install IronPDF using the NuGet Package Manager, open Visual Studio, right-click on the project, select 'Manage NuGet Packages', search for 'IronPDF', and click 'Install'.
To install iTextSharp using the NuGet Package Manager, open Visual Studio, right-click on the project, select 'Manage NuGet Packages', search for 'iTextsharp', and click 'Install'.
Yes, IronPDF can print PDF files directly using its render PDF object, allowing developers to send instructions to the default printer with just a few lines of code.
No, iTextSharp does not natively support PDF printing. It requires additional third-party libraries or code to handle the print job process.
IronPDF is popular due to its user-friendly interface, comprehensive documentation, and the wide range of functionalities it offers, making it easy to integrate PDF functionality into .NET applications.
For more information about printing PDFs using IronPDF, you can visit the IronPDF website and explore examples on paper printing PDFs.