IRONSOFTWAREHOME
USING IRONOCR

How to OCR a PDF in C#: Extract Text from Scanned Documents with .NET

Kannaopat Udonpant
Kannapat Udonpant
Updated: August 1, 2026

Scanned PDF documents present a persistent challenge for .NET developers: text exists only as images, making it impossible to search, copy, or process programmatically. Optical Character Recognition (OCR) solves this by converting scanned images into editable and searchable data -- transforming paper documents, camera-captured images, or any image-based PDF file into machine-readable text. Whether the goal is digitizing paper archives, automating data extraction, or building document processing pipelines, the ability to perform OCR on PDF files in C# is a critical capability.

IronOCR is a .NET OCR library built on the Tesseract 5 engine with additional accuracy enhancements. It lets developers extract text from any PDF document -- scanned or otherwise -- with a small number of lines of code. This article walks through the core workflows: basic PDF OCR, page-selective processing, region-targeted extraction, and image preprocessing for challenging scans.

How Do You Perform OCR on a PDF in C#?

The fastest path to PDF text extraction in .NET starts with installing IronOCR via NuGet. Open a terminal in your project directory and run:

dotnet add package IronOcr

With the package installed, the following top-level statement program reads a scanned PDF and prints its extracted text:

using IronOcr;

// Initialize the OCR engine
var ocr = new IronTesseract();

// Load the PDF and perform OCR
using var input = new OcrInput();
input.LoadPdf("scanned-report.pdf");

// Run recognition
OcrResult result = ocr.Read(input);

// Access the extracted text
string text = result.Text;
Console.WriteLine(text);

The IronTesseract class wraps Tesseract 5 with .NET-native optimizations for both .NET Core and .NET Framework targets. The OcrInput object manages PDF loading and internal page rendering. When Read is called, the OCR process analyzes each page and returns an OcrResult containing the full extracted text, plus structured data about paragraphs, lines, words, and their pixel coordinates.

The result can be written to a text file, passed to downstream processing logic, stored in a database, or fed into a document indexing pipeline. For further reading on the underlying engine, see the Tesseract OCR documentation and the IronOCR API reference.

Input

How to OCR a PDF: Extract Text from Scanned Documents with C# .NET OCR PDF: Image 1 - Sample PDF Input

Output

How to OCR a PDF: Extract Text from Scanned Documents with C# .NET OCR PDF: Image 2 - Console Output

How Do You Read Specific Pages from a PDF?

Processing every page of a long document wastes time and memory when only certain pages contain relevant content. IronOCR lets you target specific pages by passing zero-based page indices to LoadPdf:

using IronOcr;
using System.Collections.Generic;

var ocr = new IronTesseract();

// Specify pages to process (zero-based: 0 = first page)
var targetPages = new List<int> { 0, 2, 4 };

using var input = new OcrInput();
input.LoadPdf("lengthy-document.pdf", pageIndices: targetPages);

OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);

Selective page loading reduces both processing time and memory consumption, which matters when working with multi-hundred-page archives where only a handful of pages contain the data needed. The zero-based index convention matches standard .NET collections: page index 0 is the first page of the document.

For documents where the relevant pages are not known in advance, consider running a fast full-document pass first with reduced DPI to identify page numbers, then re-running with full settings on only those pages.

Learn more about page-level control in the IronOCR page selection documentation.

How Do You Extract Data from a Specific Region of a Page?

Invoice processing, form digitization, and structured document parsing frequently require extracting text from a defined area rather than scanning an entire page. IronOCR supports region-targeted OCR through the ContentAreas parameter, which accepts an array of Rectangle objects specifying which portions of each page to analyze:

using IronOcr;
using IronSoftware.Drawing;

var ocr = new IronTesseract();

// Define the scan region: X, Y, Width, Height (all in pixels from top-left)
var invoiceFields = new Rectangle[]
{
    new Rectangle(130, 290, 250, 50)   // Invoice number field
};

using var input = new OcrInput();
input.LoadPdf("invoice.pdf", contentAreas: invoiceFields);

OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);

The Rectangle constructor takes four integer parameters: the X coordinate, Y coordinate, width, and height -- all measured in pixels from the top-left corner of the rendered page. Targeting a small region rather than a full page reduces both OCR time and the chance of the engine picking up surrounding noise or unrelated text fields.

For batch invoice processing workflows, combine region extraction with iteration over result.Pages to pull structured data from the same field position across hundreds of documents. Each page result exposes the recognized text for its content area independently.

The IronOCR content areas example provides additional configuration options for multi-region scenarios.

Input

How to OCR a PDF: Extract Text from Scanned Documents with C# .NET OCR PDF: Image 3 - Sample Invoice

Output

How to OCR a PDF: Extract Text from Scanned Documents with C# .NET OCR PDF: Image 4 - Extracted Data Output

How Do You Improve OCR Accuracy on Scanned Documents?

Real-world scanned documents frequently arrive with quality problems: skewed pages, low resolution, or digital noise introduced by the scanning hardware or software. IronOCR includes a set of image preprocessing filters that correct these issues before the recognition engine runs:

using IronOcr;

var ocr = new IronTesseract();

using var input = new OcrInput();
// Load PDF at higher DPI for improved text recognition on small fonts
input.LoadPdf("poor-quality-scan.pdf", dpi: 300);

// Apply image correction filters
input.Deskew();    // Automatically straighten rotated pages
input.DeNoise();   // Remove scanning artifacts and speckles

OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);

The dpi parameter controls the resolution at which PDF pages are rendered before recognition runs. Higher values -- 200 to 300 DPI -- improve accuracy for documents with small or dense text, at the cost of slightly more memory during processing. The Deskew method detects and corrects page rotation automatically. DeNoise removes speckles and artifacts that can confuse the character recognition step.

For documents requiring more aggressive image correction, IronOCR also provides contrast enhancement, binarization (converting pages to black-and-white), and scale adjustments. Combining multiple filters in sequence can recover usable text from scans that would otherwise produce garbled output. Review the IronOCR image filters reference for the complete list of available preprocessing operations.

How Do You Handle Password-Protected and Multi-Format Documents?

IronOCR is not limited to standard PDF files. The library handles a range of input scenarios that appear frequently in document processing workflows.

Password-protected PDFs are supported by passing credentials during input construction:

using IronOcr;

var ocr = new IronTesseract();

using var input = new OcrInput();
input.LoadPdf("protected.pdf", password: "secret123");

OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);

Image formats -- PNG, JPEG, TIFF, BMP, GIF, and multipage TIFF -- are loaded with the corresponding LoadImage or LoadImageFrames methods. The same preprocessing filters and region targeting options apply regardless of input format.

Multi-language documents are handled through IronOCR's language pack system. The library ships with English by default and supports more than 125 additional language packs covering Latin, Cyrillic, CJK, Arabic, and other scripts. Load additional languages before calling Read:

var ocr = new IronTesseract();
ocr.Language = OcrLanguage.German;

For documents mixing multiple languages on the same page, MultiLanguage mode is available. This is particularly valuable for invoice processing in international environments where headers, line items, and addresses may appear in different languages.

Deployment works across Windows, Linux, macOS, and cloud environments including Azure and Docker containers.

How Do You Create Searchable PDFs from Scanned Documents?

Beyond extracting text into strings, IronOCR can produce searchable PDF output -- a PDF where the original scanned image is preserved as the visual layer while an invisible text layer is embedded for search and copy operations. This is the standard format produced by professional document scanners.

The IronOCR searchable PDF feature accepts an OcrResult and writes a new PDF file:

using IronOcr;

var ocr = new IronTesseract();

using var input = new OcrInput();
input.LoadPdf("scanned-archive.pdf");

OcrResult result = ocr.Read(input);

// Save as a searchable PDF
result.SaveAsSearchablePdf("output-searchable.pdf");

The output file can be opened in any PDF reader. Text selection, search, and copy operations work on the embedded text layer while the original scan appearance is preserved. This format is commonly required for compliance archives, legal document repositories, and enterprise content management systems.

For additional output formats, the OcrResult object also exposes per-page confidence scores, word-level bounding boxes, and structured paragraph data -- all useful for downstream classification or indexing tasks.

How Do You Read Barcodes and QR Codes Alongside Text?

Document processing pipelines often need to extract both human-readable text and machine-readable codes from the same document. IronOCR can detect and decode barcodes and QR codes during the same OCR pass, without requiring a separate library.

Enable barcode reading on the IronTesseract instance before processing:

using IronOcr;

var ocr = new IronTesseract();
ocr.Configuration.ReadBarCodes = true;

using var input = new OcrInput();
input.LoadPdf("shipment-labels.pdf");

OcrResult result = ocr.Read(input);

// Access recognized text
Console.WriteLine(result.Text);

// Access barcode data
foreach (var barcode in result.Barcodes)
{
    Console.WriteLine($"Type: {barcode.Format}, Value: {barcode.Value}");
}

This is particularly useful for shipping label processing, inventory management, and any workflow where barcodes and printed text appear together on scanned documents. The IronOCR barcode reading guide covers supported formats including Code 128, QR codes, Data Matrix, and PDF417.

What Is the Difference Between IronOCR Input Types?

IronOCR provides two main approaches for loading PDF files, each suited to different scenarios:

IronOCR PDF Input Methods Compared
ApproachClassBest ForNotes
General inputOcrInput.LoadPdf()Most use casesSupports all preprocessing filters, page selection, content areas
PDF-specificOcrPdfInputSimple scenariosConvenience wrapper; fewer configuration options
Image filesOcrInput.LoadImage()PNG, JPEG, TIFF, BMPSame preprocessing and region targeting as PDF input
Multipage TIFFOcrInput.LoadImageFrames()Fax archives, scanner outputProcesses each frame as a separate page

For most production scenarios, OcrInput.LoadPdf() is the recommended approach because it exposes the full preprocessing and configuration API. OcrPdfInput works well for quick prototyping or situations where the default settings are sufficient.

What Are Your Next Steps?

The code examples above cover the core IronOCR workflows for PDF OCR in C#. Here is a brief checklist for taking the next step:

  • Install the package: dotnet add package IronOcr or search for IronOCR on NuGet
  • Run the basic example: Confirm text extraction from a sample PDF before building out full pipeline logic
  • Apply preprocessing: If working with scanned documents, add Deskew and DeNoise calls and test with representative samples
  • Explore additional features: Searchable PDF output, barcode reading, multi-language support, and structured data output
  • Review deployment guidance: Azure, Docker, and Linux deployment articles cover environment-specific configuration
  • Try the free trial: Start a free trial to test the full feature set before committing to a license
  • Get a license: IronOCR licensing options cover individual developers through enterprise deployments, with royalty-free redistribution

For questions about specific use cases, the IronOCR how-to library provides step-by-step articles covering dozens of scenarios. The full API surface is documented in the IronOCR API reference.

Related Articles

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