IRONSOFTWAREHOME

How to Read PDFs in C# with IronOCR

Curtis Chau
Curtis Chau
Updated: August 2, 2026

IronOCR enables you to extract text from PDF files in C# with a single line of code, supporting all PDF versions and providing accurate OCR results through its Tesseract-based engine.

PDF stands for "Portable Document Format." It is a file format developed by Adobe that preserves the fonts, images, graphics, and layout of any source document, regardless of the application and platform used to create them. PDF files are typically used for sharing and viewing documents in a consistent format, irrespective of the software or hardware used to open them. IronOCR handles various versions of PDF documents, from older PDF 1.0 specifications to the latest PDF 2.0 standards.

Quickstart: OCR a PDF File in Seconds

Configure OCR quickly with IronOCR by constructing an OcrPdfInput that points to your PDF, then call Read. This example demonstrates text extraction from a PDF using IronOCR.

  1. 1Install IronOCR with NuGet Package Manager

    PM > Install-Package IronOcr

  2. 2Copy and run this code snippet.

    using var result = new IronOcr.IronTesseract().Read(new IronOcr.OcrPdfInput("document.pdf", OcrContent: PdfContents.TextAndImages));
    C#
  3. 3Deploy to test on your live environment

    Start using IronOCR in your project today with a free trial
    arrow pointer

How Do I Read an Entire PDF File?

Begin by instantiating the IronTesseract class to perform OCR. Then, utilize a 'using' statement to create an OcrPdfInput object, passing the PDF file path to it. Finally, perform OCR using the Read method. This approach works with both scanned PDFs (image-based) and searchable PDFs (text-based), suitable for extracting text from various PDF types.

/* :path=/static-assets/ocr/content-code-examples/how-to/input-pdfs-read-pdf.cs */
using IronOcr;

// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();

// Add PDF
using var pdfInput = new OcrPdfInput("Potter.pdf");
// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(pdfInput);

// Access the extracted text
string extractedText = ocrResult.Text;
System.Console.WriteLine(extractedText);
Split view showing formatted Harry Potter text vs extracted plain text output demonstrating PDF text extraction

In most cases, there's no need to specify the DPI property. However, providing a high DPI number in the construction of OcrPdfInput can enhance reading accuracy. The default DPI setting is typically sufficient for most standard PDF documents, but specialized documents may benefit from adjustment.

When Should I Adjust the DPI Settings?

DPI (Dots Per Inch) settings become crucial when dealing with low-resolution scanned documents or PDFs containing small text. For optimal results, consider adjusting DPI settings when:

  • Working with scanned documents below 200 DPI
  • Processing historical or archival PDFs
  • Dealing with complex layouts or small fonts
  • Encountering accuracy issues with default settings

A DPI of 300 is recommended for most OCR operations, while 600 DPI may be necessary for documents with very small text or intricate details.

What File Formats Does IronOCR Support Besides PDF?

IronOCR provides comprehensive support for numerous file formats beyond PDFs. You can process images in various formats including:

  • JPEG/JPG for standard photographs
  • PNG for images with transparency
  • TIFF for multi-page documents
  • BMP for uncompressed images
  • GIF for simple graphics

Additionally, IronOCR can handle PDF streams directly from memory, suitable for web applications and cloud services.

Working with PDF Content Types

When processing PDFs, you can optimize performance by specifying the content type. The PdfContents enum allows you to target specific content:

// For PDFs that contain text (faster processing)
var textOnlyPdf = new OcrPdfInput("document.pdf", OcrContent: PdfContents.TextAndImages);

// For image-only PDFs (scanned documents)
var imageOnlyPdf = new OcrPdfInput("scanned.pdf", OcrContent: PdfContents.OnlyImages);

// For mixed content (default)
var mixedPdf = new OcrPdfInput("mixed.pdf", OcrContent: PdfContents.TextAndImages);
C#

How Do I Read Specific Pages from a PDF?

When reading specific pages from a PDF document, specify the page index number for import. To do this, pass the list of page indices to the PageIndices parameter when constructing the OcrPdfInput. Keep in mind that page indices use zero-based numbering. This feature is particularly useful when working with large documents where only certain pages contain relevant information.

using IronOcr;
using System.Collections.Generic;

// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();

// Create page indices list
List<int> pageIndices = new List<int>() { 0, 2 };

// Add PDF
using var pdfInput = new OcrPdfInput("Potter.pdf", PageIndices: pageIndices);
// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(pdfInput);

Why Does Page Numbering Start at Zero?

Zero-based indexing is a standard convention in C# and most programming languages. This means the first page is index 0, the second page is index 1, and so on. This consistency with array indexing makes it easier for developers to work with page collections programmatically. When converting from human-readable page numbers (1, 2, 3...) to indices, simply subtract 1 from the page number.

How Can I Read Non-Consecutive Pages?

Reading non-consecutive pages is straightforward with IronOCR. Simply add the desired page indices to your list in any order. For example:

// Read pages 1, 3, 5, and 10 (using zero-based indices)
List<int> pageIndices = new List<int>() { 0, 2, 4, 9 };

// Or use LINQ for range-based selection
var evenPages = Enumerable.Range(0, 10).Where(x => x % 2 == 0).ToList();

The OCR engine will process only the specified pages, significantly improving performance for large documents.

What Happens If I Specify Invalid Page Numbers?

If you specify page indices that exceed the document's page count, IronOCR will throw an exception. Implement error handling or validate page counts before processing. You can check the total page count of a PDF before performing OCR to ensure your indices are valid.

How Do I OCR a Specific Region of a PDF?

By narrowing down the area to be read, you can significantly enhance the reading efficiency. To achieve this, specify the precise region of the imported PDF that needs to be read. In the code example below, IronOCR focuses solely on extracting the chapter number and title. This technique, similar to defining OCR regions for images, improves both speed and accuracy.

using IronOcr;
using IronSoftware.Drawing;
using System;

// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();

// Specify crop regions
Rectangle[] scanRegions = { new Rectangle(550, 100, 600, 300) };

// Add PDF
using (var pdfInput = new OcrPdfInput("Potter.pdf", ContentAreas: scanRegions))
{
    // Perform OCR
    OcrResult ocrResult = ocrTesseract.Read(pdfInput);

    // Output the result to console
    Console.WriteLine(ocrResult.Text);
}

How Do I Determine the Correct Rectangle Coordinates?

PDF with red rectangle selecting chapter title for OCR processing, Visual Studio console showing completed execution

Finding the correct coordinates requires understanding the PDF's coordinate system. The Rectangle constructor takes four parameters: X (horizontal position), Y (vertical position), Width, and Height. All measurements are in pixels. Tools like PDF viewers with ruler features or debugging utilities can help identify exact coordinates. Alternatively, use trial and error with small adjustments to refine your selection area.

For more precise region definition, you can utilize the highlight texts for debugging feature to visualize the areas being processed.

Can I Specify Multiple Regions in One Operation?

Yes, IronOCR supports multiple regions in a single OCR operation. Simply add multiple Rectangle objects to your array:

Rectangle[] scanRegions = { 
    new Rectangle(50, 50, 200, 100),    // Header region
    new Rectangle(50, 200, 500, 300),   // Main content region
    new Rectangle(50, 550, 200, 50)     // Footer region
};

Each region will be processed separately, and the results will be combined in the order specified.

Why Use Region-Specific OCR Instead of Full Page?

Region-specific OCR offers several advantages:

  • Performance: Processing smaller areas is significantly faster
  • Accuracy: Focusing on specific regions reduces noise from irrelevant content
  • Structure: Extract data from forms and tables more reliably
  • Cost efficiency: Less processing time means lower computational costs

This approach is particularly valuable when working with structured documents like invoices, forms, or reports where data appears in predictable locations. For complex document structures, explore reading tables in documents for specialized table extraction techniques.

What Advanced PDF OCR Features Are Available?

IronOCR offers additional capabilities for PDF processing that extend beyond basic text extraction. You can create searchable PDFs from scanned documents, preserving the original layout while adding a text layer for searching and copying. The library also supports multithreading for faster processing of large PDF collections.

For developers looking to get started with OCR in their .NET applications, exploring the simple OCR examples provides a solid foundation for understanding IronOCR's capabilities and best practices.

Handling Complex PDF Scenarios

When dealing with challenging PDF documents, IronOCR provides several advanced features:

  1. Image Preprocessing: Apply image filters to enhance text clarity
  2. Multiple Languages: Process documents containing multiple languages simultaneously
  3. Custom Configurations: Fine-tune OCR settings for specific document types
  4. Export Options: Save results in various formats including searchable PDFs and hOCR HTML

These features make IronOCR a comprehensive solution for enterprise-level PDF processing requirements.

Frequently Asked Questions

How can I extract text from a PDF using IronOCR in C#?

To extract text from a PDF with IronOCR, you instantiate the IronTesseract class and use the OcrPdfInput to specify your PDF file. Then, call the Read method to perform OCR and access the extracted text.

What are the benefits of using IronOCR for processing scanned PDFs?

IronOCR provides accurate OCR results for scanned PDFs by leveraging its Tesseract-based engine, supporting both image-based and text-based PDFs.

Can IronOCR handle different PDF versions?

Yes, IronOCR supports a wide range of PDF versions, from the older PDF 1.0 specifications to the latest PDF 2.0 standards, ensuring robust compatibility.

How does adjusting DPI settings in IronOCR affect text extraction?

Adjusting DPI settings in IronOCR can enhance OCR accuracy, especially for low-resolution documents, complex layouts, or small fonts, with a recommended setting of 300 or 600 DPI for challenging documents.

What other file formats can IronOCR process besides PDFs?

IronOCR can process various image formats including JPEG, PNG, TIFF, BMP, and GIF, in addition to PDF streams from memory.

How do you read specific pages from a PDF using IronOCR?

To read specific pages in a PDF, specify the page index numbers using the PageIndices parameter in the OcrPdfInput object. This enables targeted page processing for efficiency.

What are the advantages of using region-specific OCR over full-page OCR?

Region-specific OCR improves performance by focusing on relevant areas, enhancing accuracy and reducing noise from irrelevant content. It is especially useful for forms and structured documents.

What advanced OCR features does IronOCR offer for PDFs?

IronOCR provides features such as creating searchable PDFs, multithreading for faster processing, image preprocessing, and support for multiple languages, catering to complex document processing needs.

How do you handle invalid page numbers in IronOCR?

If invalid page numbers are specified in IronOCR, it will throw an exception. It is recommended to implement error handling or verify page counts prior to processing.

Can IronOCR process non-consecutive pages from a PDF?

Yes, IronOCR can handle non-consecutive pages by specifying the desired page indices in a list. This allows for selective processing of pages in any order.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...
Read More

Ready to Get Started?

Nuget Downloads 6,236,385Version:2026.9just released

Get your FREE

30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
bullet_testTest in production
without watermarks
bullet_calendar30 days fully
functional product
bullet_support24/5 technical
support during trial
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronOcr
nuget.org/packages/IronOcr/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronOCR"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronOCR to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronOCR.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required