Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
PDF (Portable Document Format) is a widely used file format for sharing documents consistently and securely. Reading and manipulating such files in C# is a common requirement in various applications, such as document management systems, reporting tools, and more. In this article, we will compare two popular libraries for reading PDF files in C#: IronPDF and iTextSharp (the latest .NET library iText).
IronPDF is a comprehensive C# library from Iron Software that provides a wide range of features for working with PDF files. It allows developers to create, edit, and manipulate PDF documents seamlessly. IronPDF is known for its simplicity and ease of use, making it an excellent choice for developers who need to integrate PDF functionality into their applications quickly.
iTextSharp is another popular library for working with PDF files in C#. It has been around for quite some time and is widely used in the industry. iText provides a rich set of features for creating and manipulating PDF documents. It is known for its flexibility and extensibility, making it suitable for complex PDF-related tasks.
Begin by setting up a C# Console Application. Open Visual Studio and select Create a new project. Select Console Application type.
Provide the project name as shown below.
Select the required .NET version for the project.
Once this is done, Visual Studio will generate a new project.
iTextSharp can be installed from the NuGet Package Manager. The latest version is available as an iText package.
Or from the Visual Studio Package Manager as shown below. Search for iText in Package Manager and click Install.
IronPDF can be installed from the NuGet Package Manager as shown below.
Or from the Visual Studio package manager as shown below. Search for IronPDF in Package Manager and click Install.
Add the below code to the program.cs file and provide a sample PDF document which has the below content.
using IronPdf;
Console.WriteLine("Comparison of IronPDF And itextsharp Read PDF Files in C#");
// pdfreader reader
ReadUsingIronPDF.Read();
public class ReadUsingIronPDF
{
public static void Read()
{
// read from specific location
string filename = "C:\\code\\articles\\ITextSharp\\ITextSharpIronPdfDemo\\Example.pdf";
var pdfReader = PdfDocument.FromFile(filename);
// Get all text to put in a search index using new simpletextextractionstrategy
var allText = pdfReader.ExtractAllText();
Console.WriteLine("------------------Text From PDF-----------------");
Console.WriteLine(allText);
Console.WriteLine("------------------Text From PDF-----------------");
var allIMages = pdfReader.ExtractAllImages();
Console.WriteLine("------------------Image Count From PDF-----------------");
Console.WriteLine($"Total Images={allIMages.Count()}");
Console.WriteLine("------------------Image Count From PDF-----------------");
Console.WriteLine("------------------one Page Text From PDF page-----------------");
var pageCount = pdfReader.PageCount;
for (int page = 0; page < pageCount; page++)
{
string Text = pdfReader.ExtractTextFromPage(page);
Console.WriteLine(Text);
}
}
}
using IronPdf;
Console.WriteLine("Comparison of IronPDF And itextsharp Read PDF Files in C#");
// pdfreader reader
ReadUsingIronPDF.Read();
public class ReadUsingIronPDF
{
public static void Read()
{
// read from specific location
string filename = "C:\\code\\articles\\ITextSharp\\ITextSharpIronPdfDemo\\Example.pdf";
var pdfReader = PdfDocument.FromFile(filename);
// Get all text to put in a search index using new simpletextextractionstrategy
var allText = pdfReader.ExtractAllText();
Console.WriteLine("------------------Text From PDF-----------------");
Console.WriteLine(allText);
Console.WriteLine("------------------Text From PDF-----------------");
var allIMages = pdfReader.ExtractAllImages();
Console.WriteLine("------------------Image Count From PDF-----------------");
Console.WriteLine($"Total Images={allIMages.Count()}");
Console.WriteLine("------------------Image Count From PDF-----------------");
Console.WriteLine("------------------one Page Text From PDF page-----------------");
var pageCount = pdfReader.PageCount;
for (int page = 0; page < pageCount; page++)
{
string Text = pdfReader.ExtractTextFromPage(page);
Console.WriteLine(Text);
}
}
}
Imports IronPdf
Console.WriteLine("Comparison of IronPDF And itextsharp Read PDF Files in C#")
' pdfreader reader
ReadUsingIronPDF.Read()
'INSTANT VB TODO TASK: Local functions are not converted by Instant VB:
'public class ReadUsingIronPDF
'{
' public static void Read()
' {
' ' read from specific location
' string filename = "C:\code\articles\ITextSharp\ITextSharpIronPdfDemo\Example.pdf";
' var pdfReader = PdfDocument.FromFile(filename);
' ' Get all text to put in a search index using new simpletextextractionstrategy
' var allText = pdfReader.ExtractAllText();
' Console.WriteLine("------------------Text From PDF-----------------");
' Console.WriteLine(allText);
' Console.WriteLine("------------------Text From PDF-----------------");
' var allIMages = pdfReader.ExtractAllImages();
' Console.WriteLine("------------------Image Count From PDF-----------------");
' Console.WriteLine(string.Format("Total Images={0}", allIMages.Count()));
' Console.WriteLine("------------------Image Count From PDF-----------------");
' Console.WriteLine("------------------one Page Text From PDF page-----------------");
' var pageCount = pdfReader.PageCount;
' for (int page = 0; page < pageCount; page++)
' {
' string Text = pdfReader.ExtractTextFromPage(page);
' Console.WriteLine(Text);
' }
' }
'}
Now to compare the read text from iTextSharp add the below code to the same program.cs file. For simplicity, we have not separated the classes into different files.
using IronPdf;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas.Parser.Listener;
using iText.Kernel.Pdf.Canvas.Parser;
Console.WriteLine("Comparison of IronPDF And Itextsharp Read PDF Files in C#");
//ReadUsingIronPDF.Read();
ReadUsingITextSharp.Read();
public class ReadUsingITextSharp
{
public static void Read()
{
string pdfFile = "C:\\code\\articles\\ITextSharp\\ITextSharpIronPdfDemo\\Example.pdf";
// Create a PDF reader
PdfReader pdfReader = new PdfReader(pdfFile);
iText.Kernel.Pdf.PdfDocument pdfDocument = new iText.Kernel.Pdf.PdfDocument(pdfReader);
// Extract plain text from the PDF
LocationTextExtractionStrategy strategy = new LocationTextExtractionStrategy();
string pdfText = PdfTextExtractor.GetTextFromPage(pdfDocument.GetPage(1), strategy);
// Display or manipulate the extracted text as needed
Console.WriteLine(pdfText);
}
}
using IronPdf;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas.Parser.Listener;
using iText.Kernel.Pdf.Canvas.Parser;
Console.WriteLine("Comparison of IronPDF And Itextsharp Read PDF Files in C#");
//ReadUsingIronPDF.Read();
ReadUsingITextSharp.Read();
public class ReadUsingITextSharp
{
public static void Read()
{
string pdfFile = "C:\\code\\articles\\ITextSharp\\ITextSharpIronPdfDemo\\Example.pdf";
// Create a PDF reader
PdfReader pdfReader = new PdfReader(pdfFile);
iText.Kernel.Pdf.PdfDocument pdfDocument = new iText.Kernel.Pdf.PdfDocument(pdfReader);
// Extract plain text from the PDF
LocationTextExtractionStrategy strategy = new LocationTextExtractionStrategy();
string pdfText = PdfTextExtractor.GetTextFromPage(pdfDocument.GetPage(1), strategy);
// Display or manipulate the extracted text as needed
Console.WriteLine(pdfText);
}
}
Imports IronPdf
Imports iText.Kernel.Pdf
Imports iText.Kernel.Pdf.Canvas.Parser.Listener
Imports iText.Kernel.Pdf.Canvas.Parser
Console.WriteLine("Comparison of IronPDF And Itextsharp Read PDF Files in C#")
'ReadUsingIronPDF.Read();
ReadUsingITextSharp.Read()
'INSTANT VB TODO TASK: Local functions are not converted by Instant VB:
'public class ReadUsingITextSharp
'{
' public static void Read()
' {
' string pdfFile = "C:\code\articles\ITextSharp\ITextSharpIronPdfDemo\Example.pdf";
' ' Create a PDF reader
' PdfReader pdfReader = New PdfReader(pdfFile);
' iText.Kernel.Pdf.PdfDocument pdfDocument = New iText.Kernel.Pdf.PdfDocument(pdfReader);
' ' Extract plain text from the PDF
' LocationTextExtractionStrategy strategy = New LocationTextExtractionStrategy();
' string pdfText = PdfTextExtractor.GetTextFromPage(pdfDocument.GetPage(1), strategy);
' ' Display or manipulate the extracted text as needed
' Console.WriteLine(pdfText);
' }
'}
To use IronPDF. Insert this key into the appsettings.json file.
"IronPdf.LicenseKey": "your license key"
To receive a trial license, please provide your email.
Choosing between IronPDF and iTextSharp depends on the specific requirements of your project. If you need a straightforward and easy-to-use library for common PDF operations, IronPDF might be the better choice. Consider factors like your application's complexity, budget, and the learning curve when making your decision.
IronPDF is designed to seamlessly integrate PDF generation into your application, effortlessly handling the conversion of formatted documents into PDFs. This versatile tool allows you to convert web forms, local HTML pages, and other web content to PDF using .NET. Users can conveniently download, email, or store documents in the cloud. Whether you need to produce invoices, quotes, reports, contracts, or other professional documents, IronPDF has you covered. Elevate your application with IronPDF's intuitive and efficient PDF generation capabilities.
9 .NET API products for your office documents