PRODUCT COMPARISONS

A Comparison of Printing PDF in C# Between Itextsharp and IronPDF

Published April 18, 2023
Share:

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.

  1. IronPDF
  2. iTextSharp

In this article, we will see how you can print PDF files using IronPDF and ITextSharp. Both of these are advanced PDF manipulation APIs.

1. IronPDF

IronPDF 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.

2. iTextSharp

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 fron 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.

3. Install IronPDF Library

Here are the steps to install the IronPDF library using the NuGet Package Manager:

  1. Open Visual Studio and create a new project or open an existing one.
  2. Right-click on the project in the Solution Explorer and select "Manage NuGet Packages".

    1

  3. In the "NuGet Package Manager" window, select the "Browse" tab.
  4. In the search bar, type "IronPDF" and hit Enter.
  5. Select "IronPdf" from the search results and click on the "Install" button.

    IronPDF NuGet package Search

  6. Review the dependencies that will be installed and click "OK" to proceed with the installation.
  7. Wait for the installation to complete. You can track the progress in the "Output" window.
  8. Once the installation is complete, the IronPDF Library will have been added to your project, so you can start using IronPDF.

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.

4. Install iTextsharp PDF Library

Here are the steps to install iTextsharp with NuGet Package Manager:

  1. Open Visual Studio and create a new or open an existing project.
  2. Right-click on the project in the Solution Explorer and select "Manage NuGet Packages".

    3

  3. In the "NuGet Package Manager" window, select the "Browse" tab.
  4. In the search bar, type "iTextsharp" and hit Enter.
  5. Select "iText 7" from the search results and click on the "Install" button.

    4

  6. Review the dependencies that will be installed and click "OK" to proceed with the installation.
  7. Wait for the installation to complete. You can track the progress in the "Output" window.
  8. Once the installation is complete, you can start using iTextsharp in your project.

That's it! You have successfully installed iTextsharp using the NuGet Package Manager.

5. Print a PDF Document using IronPDF

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; 
var renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
pdf.Print(300, true);
System.Drawing.Printing.PrintDocument printDocYouCanWorkWith = pdf.GetPrintDocument();  
using IronPdf; 
var renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
pdf.Print(300, true);
System.Drawing.Printing.PrintDocument printDocYouCanWorkWith = pdf.GetPrintDocument();  
Imports IronPdf
Private renderer = New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf")
pdf.Print(300, True)
Dim printDocYouCanWorkWith As System.Drawing.Printing.PrintDocument = pdf.GetPrintDocument()
VB   C#

The above code obtains 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.

6. Print a PDF File using iTextSharp

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 iText.Layout;
using iText.Layout.Element;
using iText.IO.Image;
using iText.Kernel.Geom;
using iText.Kernel.Utils;

public void PrintPDF(string filePath) { 
  //Create a PdfReader object
  PdfReader reader = new PdfReader("C:\Users\buttw\source\repos\Create PDF\Create PDF\bin\Debug\net5.0\bucket.pdf");

  //Create a PdfDocument object
  PdfDocument pdfDoc = new PdfDocument(reader); 

  //Create a PrintHelper object
  PrintHelper printHelper = new PrintHelper(pdfDoc);

  //Print the PDF document
  printHelper.Print(); 

  //Close the PdfDocument
  pdfDoc.Close(); 
}  
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.IO.Image;
using iText.Kernel.Geom;
using iText.Kernel.Utils;

public void PrintPDF(string filePath) { 
  //Create a PdfReader object
  PdfReader reader = new PdfReader("C:\Users\buttw\source\repos\Create PDF\Create PDF\bin\Debug\net5.0\bucket.pdf");

  //Create a PdfDocument object
  PdfDocument pdfDoc = new PdfDocument(reader); 

  //Create a PrintHelper object
  PrintHelper printHelper = new PrintHelper(pdfDoc);

  //Print the PDF document
  printHelper.Print(); 

  //Close the PdfDocument
  pdfDoc.Close(); 
}  
Imports Microsoft.VisualBasic
Imports iText.Kernel.Pdf
Imports iText.Layout
Imports iText.Layout.Element
Imports iText.IO.Image
Imports iText.Kernel.Geom
Imports iText.Kernel.Utils

Public Sub PrintPDF(ByVal filePath As String)
  'Create a PdfReader object
  Dim reader As New PdfReader("C:" & ChrW(&H).ToString() & "sers" & vbBack & "uttw\source" & vbCr & "epos\Create PDF\Create PDF" & vbBack & "in\Debug" & vbLf & "et5.0" & vbBack & "ucket.pdf")

  'Create a PdfDocument object
  Dim pdfDoc As New PdfDocument(reader)

  'Create a PrintHelper object
  Dim printHelper As New PrintHelper(pdfDoc)

  'Print the PDF document
  printHelper.Print()

  'Close the PdfDocument
  pdfDoc.Close()
End Sub
VB   C#

The above code retrieves a PDF file from a path, creates a new PDF object, and then, with the help of a print helper class, prints the document by sending it to the default printer.

7. Conclusion

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.

5

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.

< PREVIOUS
Comparison between IronPrint and IronPDF
NEXT >
PdfiumViewer Print PDF in C# (Alternative Tutorial)

Ready to get started? Version: 2024.10 just released

Free NuGet Download Total downloads: 10,762 View Licenses >