How to Batch-Process Multiple Images with Aspose.OCR FOSS for .NET
Aspose.OCR FOSS for .NET can recognize several images in one Recognize() call. This guide
shows how to queue multiple files on a single OcrInput and read back their results in
order.
Step-by-Step Guide
Step 1: Install the Package
dotnet add package Aspose.OCR.FOSSStep 2: Add Multiple Files to One OcrInput
All files added to the same OcrInput must share the same InputType. They are processed
sequentially and returned in the order they were added.
using Aspose.OCR;
var api = new AsposeOcr();
using var input = new OcrInput(InputType.SingleImage);
input.Add("page-1.jpg");
input.Add("page-2.png");Step 3: Recognize and Read Results in Order
Call AsposeOcr.Recognize() once for the whole batch, then iterate OcrOutput by index to
match each result back to the file it came from.
OcrOutput output = api.Recognize(input);
for (int index = 0; index < output.Count; index++)
{
Console.WriteLine($"Image {index + 1}");
Console.WriteLine(output[index].RecognitionText);
}OcrOutput is an ordered list of RecognitionResult, with one entry per image in the
order OcrInput.Add() was called.
Step 4: Batch a Multi-Page PDF Instead
The same batching model applies to a PDF: construct OcrInput with InputType.PDF, add
one PDF path, and Recognize() returns one RecognitionResult per page, in page order.
using var pdfInput = new OcrInput(InputType.PDF);
pdfInput.Add("multi-page-document.pdf");
OcrOutput pages = api.Recognize(pdfInput);
Console.WriteLine($"Pages recognized: {pages.Count}");Common Issues and Fixes
Mixing InputType.SingleImage and InputType.PDF paths in one OcrInput. Not
supported — each OcrInput is constructed with a single InputType and only accepts files
of that type. Use two separate OcrInput instances (and two Recognize() calls) if you
need to process both images and PDFs together.
Results appear out of order. They should not — OcrOutput preserves the exact order
OcrInput.Add() was called in. If files appear reordered, check that the calling code adds
them in the intended order before calling Recognize().
One bad file fails the entire batch. Recognize() validates every queued path before
running any model inference; if any path does not exist, the whole call throws
FileNotFoundException rather than skipping that one file. Validate paths yourself first
if partial results from a large batch are acceptable.
Frequently Asked Questions
Does batching run files in parallel?
No. Files and PDF pages are processed sequentially — there is no input-level
multithreading API. Microsoft.ML.OnnxRuntime parallelizes work only inside each
individual inference call.
Is there a limit on how many files one OcrInput can hold?
The public API does not document a fixed limit; OcrInput.Add() simply queues a path.
Very large batches are processed one file at a time, so throughput scales linearly, not in
parallel.
Can I reuse the same AsposeOcr instance across multiple batches?
Yes — AsposeOcr itself holds no per-call state; constructing a new OcrInput for each
batch and calling Recognize() on the same AsposeOcr instance is a normal pattern.