IRONSOFTWAREHOME

Processing Large Multi-Page PDFs with IronOCR

Curtis Chau
Curtis Chau
Updated: August 21, 2026

Large multi-page PDFs can push IronOCR into performance or memory trouble if the document is loaded all at once. The fix is a page-by-page workflow that keeps memory flat and avoids OutOfMemoryException.

The Problem with OcrInput.LoadPdf()

A common first attempt is to hand the whole file to LoadPdf():

ocrInput.LoadPdf("large.pdf");
C#

This loads every page at once, which is what triggers the trouble:

  • Memory spikes sharply as the entire document enters memory.
  • IronOCR's internal imaging system processes all pages simultaneously.
  • DPI defaults to 200, which drives memory use higher still when left unset.
  • The result can be System.OutOfMemoryException or resource deadlocks.

Solution

Process one page at a time with LoadPdfPage() instead of loading the whole document.

1. Get the PDF Page Count

Read the page count first with IronPdf.PdfDocument (or any open-source PDF library) so you know how many iterations you need.

2. Loop Through Pages

Drive a for loop over the page indexes and handle each page on its own.

3. Load an Individual Page

Inside the loop, call OcrInput.LoadPdfPage("file.pdf", pageIndex, dpi) to bring in a single page. When visual quality allows, drop the DPI as low as 80 to conserve memory.

4. Extract Text Per Page

Pass the input to IronTesseract.Read() to OCR that one page.

5. Build the Full Text

Concatenate each page's text into a StringBuilder as you go.

var ocr = new IronTesseract();
var pdfPath = "large.pdf";
using var pdf = IronPdf.PdfDocument.FromFile(pdfPath);
var pageCount = pdf.PageCount;
var textBuilder = new StringBuilder();
for (int i = 0; i < pageCount; i++)
{
    using var input = new OcrInput();
    input.LoadPdfPage(pdfPath, i, 80);
    var result = ocr.Read(input);
    textBuilder.Append(result.Text);
    textBuilder.Append(' '); // Add space between pages
}
Console.WriteLine(textBuilder.ToString().Trim());
C#

The using on each OcrInput releases the page's imaging data before the next iteration, so memory does not accumulate across the loop.

Compress the PDF First for Image-Heavy Files

If the page-by-page approach still isn't fast or stable enough, compress the PDF with IronPDF's Compress API before handing it to IronOCR. This cuts the amount of image data IronOCR has to process, which pays off most on scanned or image-heavy documents.

Compress the file to a stream, then load that stream straight into OcrInput:

var pdf = PdfDocument.FromFile(pdfPath);
var stream = pdf.CompressPdfToStream(CompressStructTree: true);
var ocrTesseract = new IronTesseract();
using var ocrInput = new OcrInput();
ocrInput.LoadPdfPage(stream, 1);
C#

For PDFs that carry images, lower the JpegQuality during compression to shrink the data further:

var pdf = PdfDocument.FromFile(@"D:\hugePdf.pdf");
var stream = pdf.CompressPdfToStream(JpegQuality: 75, CompressStructTree: true);
C#
Warning: When reusing the same MemoryStream across loop iterations, reset its position to 0 before each read. A stream is consumed once read, so subsequent reads fail if the position isn't reset.

Debug Tips

  • Lower the DPI (80 to 100): when visual quality allows, this cuts memory usage noticeably.
  • Avoid reading the entire PDF at once unless the file is very small.
  • Dispose objects properly with using statements to release memory early.
  • Run OCR in parallel only if the machine has enough memory and CPU headroom; be cautious with large PDFs.

Combining IronOCR with IronPDF (or another PDF utility) lets you process large documents page by page without crashing the application, keeping the workflow stable and scalable in production.

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