Skip to content

PdfOcr class

View as Markdown

Namespace: PdfNetStack.Ocr
Assembly: PdfNetStack.Ocr.dll
Package: PdfNetStack.Ocr

Makes scanned PDFs searchable: finds the image that is each page’s scan, reads it with an IOcrEngine, and lays the words over it as invisible text, so the page looks the same but selects, copies and searches.

public sealed class PdfOcr

Inheritance

object ← PdfOcr

using var engine = OnnxOcrEngine.Load();
PdfDocument doc = PdfDocument.Open("scan.pdf");
PdfOcrReport report = new PdfOcr(engine).MakeSearchable(doc);
doc.Save("scan-searchable.pdf");

Uses engine; the caller keeps ownership and disposes it.

public PdfOcr(IOcrEngine engine, PdfOcrOptions? options = null)

engine IOcrEngine

The recognizer.

options PdfOcrOptions?

Languages, limits and skipping; defaults when null.

MakeSearchable(PdfDocument, CancellationToken)

Section titled “ MakeSearchable(PdfDocument, CancellationToken)”

Reads every scanned page and adds invisible text to it.

public PdfOcrReport MakeSearchable(PdfDocument document, CancellationToken cancellationToken = default)

document PdfDocument

The document, changed in place; save it afterwards.

cancellationToken CancellationToken

Stops between pages and lines.

PdfOcrReport

Recognize(PdfDocument, CancellationToken)

Section titled “ Recognize(PdfDocument, CancellationToken)”

Reads every scanned page without changing the document.

public PdfOcrReport Recognize(PdfDocument document, CancellationToken cancellationToken = default)

document PdfDocument

The document.

cancellationToken CancellationToken

Stops between pages and lines.

PdfOcrReport