Skip to footer content
PRODUCT COMPARISONS

Extract Text From PDF in C# Using iTextSharp VS IronPDF

Extracting text from PDF documents is a common requirement in modern software projects—from processing invoices to mining content for search engines. Developers need reliable libraries that offer not only accurate results but also an efficient integration experience in C# .NET applications. Some developers use OCR (optical character recognition) tools to extract data from scanned documents and images, but sometimes the job calls for a robust text extraction tool.

But with several PDF libraries on the market, choosing the right tool can be overwhelming. Two libraries that often come up in the conversation are iTextSharp and IronPDF. Both can extract text from PDFs, but they differ significantly in usability, support, performance, and pricing. This article compares the two libraries, looking at different code samples to demonstrate how they handle text extraction, to help you decide which best fits your project.

An Overview of IronPDF and the iTextSharp Library

iTextSharp has long been a popular open-source PDF library for .NET, offering powerful tools for generating, manipulating, and extracting content. As a C# port of the Java-based iText, it provides deep control over PDF structures—ideal for advanced users. However, this flexibility comes with a steep learning curve and licensing constraints; commercial use often requires a paid license to avoid AGPL obligations.

Enter IronPDF—a modern, developer-friendly PDF library built for .NET. It streamlines common tasks like text extraction with an intuitive API, clear documentation, and responsive support. With this tool, developers can extract images and text from PDF documents with ease, create new PDF files, implement PDF security, and more.

Unlike iTextSharp, IronPDF avoids complex low-level structures, letting you work faster and more efficiently. Whether you're processing a single page or hundreds of PDFs, it keeps things simple.

It’s also actively maintained, with regular updates and a straightforward licensing model, including a free trial and affordable plans for teams and solo developers alike.

Installing and Using IronPDF

IronPDF can be installed via NuGet by running the following command in the NuGet Package Manager Console:

Install-Package IronPdf

Alternatively, you can install it via the NuGet package manager for Solution screen. To do this, navigate to "Tools > NuGet Package Manager > Manage NuGet Packages for Solution". Then, search for IronPDF, and click "Install".

Extract Text from PDF Files with IronPDF

Once installed, extracting text is straightforward:

using IronPdf;

// Load the PDF document
var pdf = PdfDocument.FromFile("invoice.pdf");

// Extract text from the PDF
string extractedText = pdf.ExtractAllText();

// Output the extracted text
Console.WriteLine(extractedText);
using IronPdf;

// Load the PDF document
var pdf = PdfDocument.FromFile("invoice.pdf");

// Extract text from the PDF
string extractedText = pdf.ExtractAllText();

// Output the extracted text
Console.WriteLine(extractedText);
Imports IronPdf

' Load the PDF document
Private pdf = PdfDocument.FromFile("invoice.pdf")

' Extract text from the PDF
Private extractedText As String = pdf.ExtractAllText()

' Output the extracted text
Console.WriteLine(extractedText)
$vbLabelText   $csharpLabel

Note: This method reads the entire PDF file and returns the text in reading order, saving hours of parsing time compared to traditional libraries.

No need to handle encodings, content streams, or manual parsing. IronPDF handles all of that internally, providing clean and accurate output with minimal setup. You could then easily save the extracted text to a new text file for further manipulation or use.

Installing the iTextSharp PDF library

To download iTextSharp's core package for PDF generation, use the following command:

Install-Package iTextSharp

You can also install iTextSharp via the Package Manager for Solution screen. To do this, you first need to go to the Tools drop-down menu, then find "NuGet Package Manager > Manage NuGet Packages for Solution". Then, simply search for iTextSharp, and click "Install".

Extract Text from PDF documents with iTextSharp

Here’s a sample to extract text from a single PDF page:

using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas.Parser;
using iText.Kernel.Pdf.Canvas.Parser.Listener;

// Define the path to your PDF
string path = "sample.pdf";

// Open the PDF reader and document
using (PdfReader reader = new PdfReader(path))
using (PdfDocument pdf = new PdfDocument(reader))
{
    // Use a simple text extraction strategy
    var strategy = new SimpleTextExtractionStrategy();

    // Extract text from the first page
    string pageText = PdfTextExtractor.GetTextFromPage(pdf.GetPage(1), strategy);

    // Output the extracted text
    Console.WriteLine(pageText);
}
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas.Parser;
using iText.Kernel.Pdf.Canvas.Parser.Listener;

// Define the path to your PDF
string path = "sample.pdf";

// Open the PDF reader and document
using (PdfReader reader = new PdfReader(path))
using (PdfDocument pdf = new PdfDocument(reader))
{
    // Use a simple text extraction strategy
    var strategy = new SimpleTextExtractionStrategy();

    // Extract text from the first page
    string pageText = PdfTextExtractor.GetTextFromPage(pdf.GetPage(1), strategy);

    // Output the extracted text
    Console.WriteLine(pageText);
}
Imports iText.Kernel.Pdf
Imports iText.Kernel.Pdf.Canvas.Parser
Imports iText.Kernel.Pdf.Canvas.Parser.Listener

' Define the path to your PDF
Private path As String = "sample.pdf"

' Open the PDF reader and document
Using reader As New PdfReader(path)
Using pdf As New PdfDocument(reader)
	' Use a simple text extraction strategy
	Dim strategy = New SimpleTextExtractionStrategy()

	' Extract text from the first page
	Dim pageText As String = PdfTextExtractor.GetTextFromPage(pdf.GetPage(1), strategy)

	' Output the extracted text
	Console.WriteLine(pageText)
End Using
End Using
$vbLabelText   $csharpLabel

This example demonstrates iTextSharp’s capability, but notice the verbosity and additional objects required to perform a simple task.

Detailed Comparison

Now that we've covered installation and basic usage, let's take a look at a more in-depth comparison of how these two libraries handle text extraction by having them extract text from a multi-paged PDF document.

Advanced Example: Extracting Text from a Page Range with IronPDF

IronPDF supports granular control over page selection and layout-aware text extraction.

using IronPdf;

// Load the PDF document
var pdf = PdfDocument.FromFile("longPdf.pdf");

// Define the page numbers to extract text from
int[] pages = new[] { 2, 3, 4 };

// Extract text from the specified pages
var text = pdf.ExtractTextFromPages(pages);

// Output the extracted text
Console.WriteLine("Extracted text from pages 2, 3, and 4:\n" + text);
using IronPdf;

// Load the PDF document
var pdf = PdfDocument.FromFile("longPdf.pdf");

// Define the page numbers to extract text from
int[] pages = new[] { 2, 3, 4 };

// Extract text from the specified pages
var text = pdf.ExtractTextFromPages(pages);

// Output the extracted text
Console.WriteLine("Extracted text from pages 2, 3, and 4:\n" + text);
Imports Microsoft.VisualBasic
Imports IronPdf

' Load the PDF document
Private pdf = PdfDocument.FromFile("longPdf.pdf")

' Define the page numbers to extract text from
Private pages() As Integer = { 2, 3, 4 }

' Extract text from the specified pages
Private text = pdf.ExtractTextFromPages(pages)

' Output the extracted text
Console.WriteLine("Extracted text from pages 2, 3, and 4:" & vbLf & text)
$vbLabelText   $csharpLabel

Advanced Example: Extracting Text from a Page Range using iTextSharp

In iTextSharp, you’ll need to manually specify the page range and extract text using PdfTextExtractor:

using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
using System.IO;
using System.Text;

// Load the PDF document
PdfReader reader = new PdfReader("longPdf.pdf");
StringBuilder textBuilder = new StringBuilder();

// Extract text from pages 2–4
for (int i = 2; i <= 4; i++)
{
    string pageText = PdfTextExtractor.GetTextFromPage(reader, i, new LocationTextExtractionStrategy());
    textBuilder.AppendLine(pageText);
}

// Output the extracted text
Console.WriteLine(textBuilder.ToString());

// Close the PDF reader
reader.Close();
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
using System.IO;
using System.Text;

// Load the PDF document
PdfReader reader = new PdfReader("longPdf.pdf");
StringBuilder textBuilder = new StringBuilder();

// Extract text from pages 2–4
for (int i = 2; i <= 4; i++)
{
    string pageText = PdfTextExtractor.GetTextFromPage(reader, i, new LocationTextExtractionStrategy());
    textBuilder.AppendLine(pageText);
}

// Output the extracted text
Console.WriteLine(textBuilder.ToString());

// Close the PDF reader
reader.Close();
Imports iTextSharp.text.pdf
Imports iTextSharp.text.pdf.parser
Imports System.IO
Imports System.Text

' Load the PDF document
Private reader As New PdfReader("longPdf.pdf")
Private textBuilder As New StringBuilder()

' Extract text from pages 2–4
For i As Integer = 2 To 4
	Dim pageText As String = PdfTextExtractor.GetTextFromPage(reader, i, New LocationTextExtractionStrategy())
	textBuilder.AppendLine(pageText)
Next i

' Output the extracted text
Console.WriteLine(textBuilder.ToString())

' Close the PDF reader
reader.Close()
$vbLabelText   $csharpLabel

Code Comparison Summary

Both IronPDF and iTextSharp are capable of advanced PDF text extraction, but their approaches differ significantly in complexity and clarity:

  • IronPDF keeps things clean and accessible. Its high-level methods like PdfDocument.ExtractAllText() allow you to extract structured content with minimal setup. The code is straightforward, making it easy to implement even for developers new to PDF processing.

  • iTextSharp, on the other hand, requires a deeper understanding of the PDF structure. Extracting text involves setting up custom render listeners, managing pages manually, and interpreting layout data line by line. While powerful, it’s more verbose and less intuitive, making IronPDF a faster and more maintainable option for most .NET projects.

But our comparison doesn't end here. Next, let's look at how these two libraries compare in other areas.

Detailed Comparison: IronPDF vs iTextSharp

When evaluating PDF text extraction libraries for .NET, developers often weigh the balance between simplicity, performance, and long-term support. Let’s break down how IronPDF and iTextSharp compare in real-world usage, especially for extracting text from PDFs in C#.

1. Ease of Use

IronPDF: Clean and Modern API

IronPDF emphasizes developer experience. Installation is easy via NuGet, and the syntax is intuitive:

using IronPdf;

// Load the PDF
var pdf = PdfDocument.FromFile("sample.pdf");

// Extract all text from every page
string extractedText = pdf.ExtractAllText();

// Output the extracted text
Console.WriteLine(extractedText);
using IronPdf;

// Load the PDF
var pdf = PdfDocument.FromFile("sample.pdf");

// Extract all text from every page
string extractedText = pdf.ExtractAllText();

// Output the extracted text
Console.WriteLine(extractedText);
Imports IronPdf

' Load the PDF
Private pdf = PdfDocument.FromFile("sample.pdf")

' Extract all text from every page
Private extractedText As String = pdf.ExtractAllText()

' Output the extracted text
Console.WriteLine(extractedText)
$vbLabelText   $csharpLabel

IronPDF abstracts the complexity behind simple method calls like ExtractAllText(), requiring no boilerplate or parsing logic.

iTextSharp: More Verbose and Lower-Level

iTextSharp requires manual parsing of each page and more effort to extract plain text.

using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
using System.IO;
using System.Text;

// Load the PDF
var reader = new PdfReader("sample.pdf");
StringBuilder text = new StringBuilder();

for (int i = 1; i <= reader.NumberOfPages; i++)
{
    text.Append(PdfTextExtractor.GetTextFromPage(reader, i));
}

// Output the extracted text
Console.WriteLine(text.ToString());
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
using System.IO;
using System.Text;

// Load the PDF
var reader = new PdfReader("sample.pdf");
StringBuilder text = new StringBuilder();

for (int i = 1; i <= reader.NumberOfPages; i++)
{
    text.Append(PdfTextExtractor.GetTextFromPage(reader, i));
}

// Output the extracted text
Console.WriteLine(text.ToString());
Imports iTextSharp.text.pdf
Imports iTextSharp.text.pdf.parser
Imports System.IO
Imports System.Text

' Load the PDF
Private reader = New PdfReader("sample.pdf")
Private text As New StringBuilder()

For i As Integer = 1 To reader.NumberOfPages
	text.Append(PdfTextExtractor.GetTextFromPage(reader, i))
Next i

' Output the extracted text
Console.WriteLine(text.ToString())
$vbLabelText   $csharpLabel

Developers need to manually loop through pages, which introduces more code and potential for bugs if edge cases arise.

2. Performance and Reliability

  • IronPDF is built on a modern rendering engine (Chromium), making it well-suited for modern PDFs, even those with embedded fonts, rotated text, and multiple layouts. Text extraction is layout-aware and preserves spacing more naturally.

  • iTextSharp, although powerful, may struggle with complex formatting. PDF files with mixed orientation or non-standard encodings may yield garbled or improperly ordered text.

3. Cost and Licensing

FeatureIronPDFiTextSharp
License TypeCommercial (Free Trial Available)AGPL (Free) / Commercial (Paid)
Pricing TransparencyPublic pricing & perpetual licensingComplex tiers and redistribution rules
SupportDedicated Support TeamCommunity support (unless licensed)
Use in Closed Source AppYes (with license)Not with AGPL

Please note
If you're building commercial or proprietary software, iTextSharp AGPL will force you to open-source your code or pay for a commercial license. IronPDF offers a more flexible licensing model for closed-source projects.

4. Developer Support and Documentation

  • IronPDF: Comes with modern documentation, video tutorials, and fast ticket-based support.

  • iTextSharp: Good documentation, but limited free support unless you're a paid customer.

5. Cross-Library Summary

CriteriaIronPDFiTextSharp
SimplicityHigh – One-liner text extractionMedium – Manual page iteration
PerformanceFast and modern parsingSlower on complex or scanned PDFs
Commercial FriendlyYes, no AGPL restrictionsAGPL limits use in closed-source apps
Support & DocsDedicated, responsiveCommunity-dependent
.NET Core SupportFullFull

Conclusion

When it comes to extracting text from PDFs in C#, both IronPDF and iTextSharp are capable tools—but they serve different types of developers. If you're looking for a modern, easy-to-integrate solution with excellent support, actively maintained features, and seamless layout preservation, IronPDF clearly stands out. It reduces development time, offers intuitive APIs, and works well across a wide range of applications within the .NET framework, from web apps to enterprise systems.

On the other hand, iTextSharp remains a strong option for developers already embedded in its ecosystem or those who require granular control over text extraction strategies. However, its steeper learning curve and lack of commercial support can slow down projects that need to scale quickly or maintain clean codebases.

For .NET developers who value speed, clarity, and reliable results, IronPDF provides a future-ready path. Whether you're building document automation tools, search engines, or internal dashboards, IronPDF’s robust features and performance will help you deliver faster and smarter.

Try IronPDF today by downloading the free trial and experience the difference for yourself. With a free trial and a developer-friendly API, you can get started in minutes.

Please note
iTextSharp is a registered trademark of its respective owner. This site is not affiliated with, endorsed by, or sponsored by iTextSharp. All product names, logos, and brands are property of their respective owners. Comparisons are for informational purposes only and reflect publicly available information at the time of writing.

Frequently Asked Questions

What are the main differences between using text extraction libraries for C#?

Using IronPDF offers a simpler and more modern API for text extraction compared to other libraries like iTextSharp, which require more manual parsing of each page. IronPDF also provides faster and more reliable performance for modern PDFs with complex layouts.

How can I install a PDF processing library in my C# project?

You can install IronPDF via NuGet by running the command 'Install-Package IronPdf' in the NuGet Package Manager Console or use the NuGet package manager for Solution screen to search and install IronPDF.

What is the licensing model for modern PDF libraries?

IronPDF offers a commercial licensing model with a free trial available. It provides a straightforward licensing model with affordable plans for teams and solo developers, and it does not impose AGPL restrictions on closed-source applications.

Can modern PDF libraries handle text extraction from multi-paged PDF documents?

Yes, IronPDF can efficiently extract text from multi-paged PDF documents and supports granular control over page selection. It uses methods like PdfDocument.ExtractTextFromPages() to handle specific page ranges.

How do text extraction capabilities of different libraries compare?

While some libraries like iTextSharp are powerful and offer deep control over PDF structures, they are more verbose and require a deeper understanding of PDF structure. IronPDF, on the other hand, provides a cleaner and more accessible approach with high-level methods for extracting structured content.

Are modern PDF libraries suitable for commercial applications?

Yes, IronPDF is suitable for commercial applications and offers a licensing model without AGPL restrictions, making it a viable option for closed-source projects.

Do modern PDF libraries offer support and documentation?

IronPDF comes with modern documentation, video tutorials, and fast ticket-based support, making it a developer-friendly option for integration into .NET projects.

How do modern PDF libraries handle complex formatting during text extraction?

IronPDF is built on a modern rendering engine that handles complex formatting effectively, preserving spacing naturally and working well with embedded fonts, rotated text, and multiple layouts.

What are the performance benefits of using modern PDF libraries?

IronPDF offers faster performance due to its modern rendering engine and layout-aware text extraction, which is particularly beneficial for PDFs with complex layouts and embedded fonts.

Which library is recommended for developers new to PDF processing?

IronPDF is recommended for developers new to PDF processing because of its intuitive API, ease of integration, and comprehensive support and documentation, making it easier to implement than other libraries like iTextSharp.

Chipego
Software Engineer
Chipego has a natural skill for listening that helps him to comprehend customer issues, and offer intelligent solutions. He joined the Iron Software team in 2023, after studying a Bachelor of Science in Information Technology. IronPDF and IronOCR are the two products Chipego has been focusing on, but his knowledge of all products is growing daily, as he finds new ways to support customers. He enjoys how collaborative life is at Iron Software, with team members from across the company bringing their varied experience to contribute to effective, innovative solutions. When Chipego is away from his desk, he can often be found enjoying a good book or playing football.