Lyo.Pdf.Ocr
1.0.2
dotnet add package Lyo.Pdf.Ocr --version 1.0.2
NuGet\Install-Package Lyo.Pdf.Ocr -Version 1.0.2
<PackageReference Include="Lyo.Pdf.Ocr" Version="1.0.2" />
<PackageVersion Include="Lyo.Pdf.Ocr" Version="1.0.2" />
<PackageReference Include="Lyo.Pdf.Ocr" />
paket add Lyo.Pdf.Ocr --version 1.0.2
#r "nuget: Lyo.Pdf.Ocr, 1.0.2"
#:package Lyo.Pdf.Ocr@1.0.2
#addin nuget:?package=Lyo.Pdf.Ocr&version=1.0.2
#tool nuget:?package=Lyo.Pdf.Ocr&version=1.0.2
Lyo.Pdf.Ocr
Glues Lyo.Pdf.Rendering (PDFium → PNG) to an IOcrEngine from Lyo.Images.Ocr and projects OCR pixel boxes back into PDF coordinate space.
Targets net10.0.
Examples
Register with DI
services.AddTesseractOcrEngineFromConfiguration(configuration); // or any IOcrEngine
services.AddPdfOcr();
Example
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();
}
}
API
PdfOcrService exposes a single method:
Task<Result<PdfOcrDocumentPage>> ReadPageAsync(
IPdfReader pdfReader,
int pageNumber1Based,
int dpi,
OcrReadRequest? ocrRequest = null,
string? pdfPassword = null,
CancellationToken cancellationToken = default);
The pipeline:
pdfReader.GetPageSizePoints(pageNumber1Based)for the PDF page dimensions.IPdfPageRasterizer.RenderPageToPngAsync(pdfReader.SourceBytes, …)for the pixel raster (and bitmap width/height).IOcrEngine.ReadAsync(pngStream, ocrRequest, …)for the per-word text and pixel-space bounding boxes (Y-up).OcrCoordinateTransforms.MapPixelBoxToPdfPoints(box, pageWidthPts, pageHeightPts, widthPx, heightPx)to lift eachOcrWordinto aPdfWord.
PdfOcrDocumentPage carries the original OcrPageResult plus the projected
IReadOnlyList<PdfWord> WordsInPdfPoints and the source page size.
Failures from either stage propagate as Result<PdfOcrDocumentPage>.Failure;
unexpected exceptions are tagged with PdfOcrErrorCodes.ReadFailed
("PDF_OCR_READ_FAILED").
Dependency injection
AddPdfOcr registers PdfOcrService as a singleton and calls AddPdfPageRasterizer if IPdfPageRasterizer is not already registered. IOcrEngine must be registered separately.
Example
For selectable-text PDFs prefer IPdfReader.Text (PdfPig) directly — OCR only helps when the PDF lacks an 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.Abstractions10.0.5— (direct, microsoft)Microsoft.Extensions.Logging.Abstractions10.0.5— (direct, microsoft)Lyo.Common— (transitive, lyo)Lyo.DataTable.Models— (transitive, lyo)Lyo.Metrics— (transitive, lyo)Lyo.Result— (transitive, lyo)Microsoft.Extensions.Configuration.Binder10.0.5— (transitive, microsoft)Microsoft.Extensions.Options.ConfigurationExtensions10.0.5— (transitive, microsoft)PDFtoImage5.2.1— (transitive, third-party)SixLabors.ImageSharp3.1.12— (transitive, third-party)System.Memory4.6.3— (transitive, microsoft, netstandard2.0)System.Text.Json10.0.5— (transitive, microsoft, netstandard2.0)
| Product | Versions 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. |
-
net10.0
- Lyo.Exceptions (>= 1.0.2)
- Lyo.Images.Ocr (>= 1.0.2)
- Lyo.Pdf.Models (>= 1.0.2)
- Lyo.Pdf.Rendering (>= 1.0.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.5)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.