Introduction

Aspose.OCR FOSS for .NET is a new open-source C# library for detecting and recognizing text in raster images and PDF documents. It is built for .NET developers who need text recognition without depending on an external OCR service, a cloud API, or any proprietary runtime.

The library is MIT licensed and has no external OCR dependency: the entire recognition pipeline — text-line detection, region refinement, and Latin-script recognition — runs locally through three ONNX models embedded directly in the assembly and executed on the CPU via Microsoft.ML.OnnxRuntime. No model download step and no network call are required at runtime.


What’s Included

Recognizing Images and PDFs Through One Entry Point

AsposeOcr.Recognize() is the single entry point for both input kinds. An OcrInput is built with InputType.SingleImage or InputType.PDF, and one or more file paths are queued with OcrInput.Add(). For InputType.PDF, every page is recognized and returned in source order.

using Aspose.OCR;
var api = new AsposeOcr();
using var input = new OcrInput(InputType.SingleImage);
input.Add("scan.png");
RecognitionResult result = api.Recognize(input)[0];
Console.WriteLine(result.RecognitionText);

Line-Level Text and Pixel Coordinates

Each RecognitionResult returns the full page text through RecognitionText, and the individual recognized lines through RecognitionLinesResult — a list of RecognitionResult.LinesResult entries, each exposing TextInLine and a System.Drawing.Rectangle in Line giving that line’s pixel coordinates in the source image.

foreach (RecognitionResult.LinesResult line in result.RecognitionLinesResult)
{
    Console.WriteLine($"{line.Line}: {line.TextInLine}");
}

Batching Multiple Files

OcrInput can hold more than one file. OcrOutput — the return value of Recognize() — is a list of RecognitionResult, one per image or PDF page, preserving the original order the files were added in.

using var input = new OcrInput(InputType.SingleImage);
input.Add("page-1.jpg");
input.Add("page-2.png");
OcrOutput output = api.Recognize(input);

Quick Start

dotnet add package Aspose.OCR.FOSS

The example below recognizes every page of a PDF with AsposeOcr.Recognize() and prints each page’s text along with its individual recognized lines and their pixel coordinates.

using Aspose.OCR;

var api = new AsposeOcr();
using var input = new OcrInput(InputType.PDF);
input.Add("document.pdf");

OcrOutput output = api.Recognize(input);

foreach (RecognitionResult page in output)
{
    Console.WriteLine(page.RecognitionText);

    foreach (RecognitionResult.LinesResult line in page.RecognitionLinesResult)
    {
        Console.WriteLine($"{line.Line}: {line.TextInLine}");
    }
}

The only supported input types are InputType.SingleImage and InputType.PDF; any other input type throws NotSupportedException.


Open Source & Licensing

Aspose.OCR FOSS for .NET is released under the MIT license. It can be used, modified, and redistributed — including in commercial products — without additional licensing fees. The source is available on GitHub.


Getting Started