PdfNetStack.Ocr 1.1.0

dotnet add package PdfNetStack.Ocr --version 1.1.0
                    
NuGet\Install-Package PdfNetStack.Ocr -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PdfNetStack.Ocr" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PdfNetStack.Ocr" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="PdfNetStack.Ocr" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PdfNetStack.Ocr --version 1.1.0
                    
#r "nuget: PdfNetStack.Ocr, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package PdfNetStack.Ocr@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PdfNetStack.Ocr&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=PdfNetStack.Ocr&version=1.1.0
                    
Install as a Cake Tool

PdfNetStack.Ocr

Make scanned PDFs searchable in .NET. PdfNetStack.Ocr finds the scan on each page, reads it with the PP-OCRv5 models on ONNX Runtime, and lays the words over it as invisible text: the page looks the same, and now selects, copies and searches. Latin and Arabic script. Built on PdfNetStack.

dotnet add package PdfNetStack.Ocr
dotnet add package PdfNetStack.Ocr.Models    # the models, about 21 MB
using PdfNetStack;
using PdfNetStack.Ocr;

using var engine = OnnxOcrEngine.Load();     // the models from PdfNetStack.Ocr.Models
PdfDocument doc = PdfDocument.Open("scan.pdf");
PdfOcrReport report = new PdfOcr(engine).MakeSearchable(doc);
doc.Save("scan-searchable.pdf");
Console.WriteLine(report.Text);

Runs on .NET 8 and later, and on .NET Framework 4.6.2+ through .NET Standard 2.0 (64 bit only; see Limits).

Usage

// Latin and Arabic: each line keeps the reading its recognizer is most confident in.
var languages = new[] { "latin", "arabic" };
using var engine = OnnxOcrEngine.Load(new OnnxOcrEngineOptions { Languages = languages });
var ocr = new PdfOcr(engine, new PdfOcrOptions
{
    Languages = languages,
    MinimumConfidence = 0.5,      // lines read with less confidence are left out
    MaxDegreeOfParallelism = 4,   // pages recognized at once
    MaxOcrDpi = 400,              // finer scans are averaged down first
});

// Recognize reads without changing the document: lines and words with their boxes in page space.
PdfOcrReport report = ocr.Recognize(doc);
foreach (PdfOcrPage page in report.Pages)
{
    Console.WriteLine($"page {page.Index + 1}: {page.Status} {page.Reason}");
    foreach (OcrLine line in page.Lines) Console.WriteLine($"  {line.Text} ({line.Confidence:P0})");
}

// Models kept in a folder of your own, without PdfNetStack.Ocr.Models.
using var custom = OnnxOcrEngine.Load("path/to/models");

What it does

  • Finds the scan. The image that covers the page, or several images that cover it together: strips or tiles side by side, or a text mask over a background, as some scanners write them. Pieces are put back together in page space, one at a time, so memory stays at one page plus one piece.
  • Turns it upright from its placement and the page's /Rotate; a line orientation model turns upside down lines.
  • Reads Latin and Arabic script (Arabic also covers Persian and Urdu), right to left text in logical order, with word boxes mapped back to the page.
  • Writes invisible text (render mode 3) over each word, stretched to its box, with a glyphless font that covers every script. Pages that already show text are left alone.
  • Plugs in other engines through IOcrEngine.

Safety

Detection, decoding and right to left ordering are managed code: the native runtime only ever sees float tensors, never PDF bytes. Pixel counts are checked before anything is decoded. Model files are checked against pinned SHA-256 hashes before they load, and nothing is downloaded at run time. ONNX Runtime's telemetry is turned off before the first model loads.

Limits

  • Pages need a decodable scan covering at least half the page (MinimumCoverage); vector art is not rasterized. Scans in several pieces must be upright or turned by quarter turns.
  • ONNX Runtime ships native builds for Windows, Linux and macOS on x64 and arm64, except macOS x64. On Linux and macOS set ORT_DISABLE_TELEMETRY=1 before the process starts for the runtime to send nothing at all.
  • On .NET Framework the app must run 64 bit and reference Microsoft.ML.OnnxRuntime itself, so its native runtime is copied next to the app.
  • Recognition uses floating point on the CPU, so results can differ slightly between machines.

By Jamal Abdelkhalek, JADEV. MIT license. Depends on ONNX Runtime (MIT).

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 0 11/5/2026