Lyo.Pdf.Ocr 2.0.0

dotnet add package Lyo.Pdf.Ocr --version 2.0.0
                    
NuGet\Install-Package Lyo.Pdf.Ocr -Version 2.0.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="Lyo.Pdf.Ocr" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Lyo.Pdf.Ocr" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Lyo.Pdf.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 Lyo.Pdf.Ocr --version 2.0.0
                    
#r "nuget: Lyo.Pdf.Ocr, 2.0.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 Lyo.Pdf.Ocr@2.0.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=Lyo.Pdf.Ocr&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Lyo.Pdf.Ocr&version=2.0.0
                    
Install as a Cake Tool

Lyo.Pdf.Ocr

PNG-renders a PDF page with Lyo.Pdf.Rendering (PDFium), runs an IOcrEngine from Lyo.Images.Ocr, then lifts OCR pixel boxes into PDF points.

Targets net10.0.

Examples

Add Pdf OCR in DI

services.AddTesseractOcrEngineFromConfiguration(configuration); // or any IOcrEngine
services.AddPdfOcr();

Read one page

public sealed class Worker(PdfOcrService pdfOcr, IPdfService pdfService)
{
    public async Task<PdfOcrDocumentPage> RunAsync(byte[] pdfBytes, CancellationToken ct)
    {
        await using var reader = await pdfService.OpenFromBytesAsync(pdfBytes, ct);
        var result = await pdfOcr.ReadPageAsync(reader, pageNumber1Based: 1, dpi: 200, cancellationToken: ct);
        return result.ValueOrThrow();
    }
}

ReadPageAsync pipeline

PdfOcrService has one method:

Task<Result<PdfOcrDocumentPage>> ReadPageAsync(
    IPdfReader pdfReader,
    int pageNumber1Based,
    int dpi,
    OcrReadRequest? ocrRequest = null,
    string? pdfPassword = null,
    CancellationToken cancellationToken = default);

Steps:

  1. pdfReader.GetPageSizePoints(pageNumber1Based) for the PDF page dimensions.
  2. IPdfPageRasterizer.RenderPageToPngAsync(pdfReader.SourceBytes, …) for the pixel raster (and bitmap width/height).
  3. IOcrEngine.ReadAsync(pngStream, ocrRequest, …) for the per-word text and pixel-space bounding boxes (Y-up).
  4. OcrCoordinateTransforms.MapPixelBoxToPdfPoints(box, pageWidthPts, pageHeightPts, widthPx, heightPx) to lift each OcrWord into a PdfWord.

PdfOcrDocumentPage holds the original OcrPageResult, the projected IReadOnlyList<PdfWord> WordsInPdfPoints, and the source page size.

Either stage can fail as Result<PdfOcrDocumentPage>.Failure; unexpected exceptions are tagged with PdfOcrErrorCodes.ReadFailed ("PDF_OCR_READ_FAILED").

DI registration

AddPdfOcr adds PdfOcrService as a singleton and, if IPdfPageRasterizer is missing, calls AddPdfPageRasterizer. Register IOcrEngine yourself.

When OCR is worth it

Selectable-text PDFs should use IPdfReader.Text (PdfPig) instead. OCR is useful only when the PDF has no embedded text layer.

Dependencies

Generated from ProjectReference / PackageReference (same model as docs/Lyo.ProjectGraph.html).

  • Lyo.Exceptions (direct, lyo)
  • Lyo.Images.Ocr (direct, lyo)
  • Lyo.Pdf.Models (direct, lyo)
  • Lyo.Pdf.Rendering (direct, lyo)
  • Microsoft.Extensions.DependencyInjection.Abstractions 10.0.5 (direct, microsoft)
  • Microsoft.Extensions.Logging.Abstractions 10.0.5 (direct, microsoft)
  • Lyo.Common.Core (transitive, lyo)
  • Lyo.Common.Metadata (transitive, lyo)
  • Lyo.Configuration (transitive, lyo)
  • Lyo.DataTable.Models (transitive, lyo)
  • Lyo.Metrics (transitive, lyo)
  • Lyo.Result (transitive, lyo)
  • Microsoft.Bcl.AsyncInterfaces 10.0.5 (transitive, microsoft, netstandard2.0)
  • Microsoft.Extensions.Configuration.Binder 10.0.5 (transitive, microsoft)
  • PDFtoImage 5.2.1 (transitive, third-party)
  • SixLabors.ImageSharp 3.1.12 (transitive, third-party)
  • System.Memory 4.6.3 (transitive, microsoft, netstandard2.0)
  • System.Text.Json 10.0.5 (transitive, microsoft, netstandard2.0)
Product Compatible and additional computed target framework versions.
.NET 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. 
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
2.0.0 39 9/9/2026
1.0.13 102 8/25/2026
1.0.11 84 8/23/2026
1.0.9 105 8/22/2026
1.0.6 91 8/20/2026
1.0.4 100 8/20/2026
1.0.3 97 8/19/2026
1.0.2 93 8/19/2026
1.0.1 90 8/18/2026
1.0.0 116 8/16/2026