PDFium Delphi Component Docs

ApplyOcrSearchLayer method

Component: TPdf  ·  Unit: PDFium
Adds an invisible searchable text layer to scanned pages through an application OCR provider

Syntax

function ApplyOcrSearchLayer(
  const Provider: IPdfOcrProvider;
  const Options: TPdfOcrOptions;
  out Report: TPdfOcrReport;
  const CancellationToken: IPdfCancellationToken = nil): Boolean;

Provider contract

The library renders each selected page through PDFium and passes a compact top-down popfBgra32 image to IPdfOcrProvider.RecognizePage

The provider returns TPdfOcrWord values whose Quad coordinates use pixel units with the origin at the image top left

Text confidence must be in the range 0 through 1 and quadrilateral points must remain inside the supplied image

Output behaviour

Options and budgets

FirstPage and LastPage select an inclusive range, while zero selects the document boundary

SkipPagesWithText avoids duplicating an existing searchable layer and ContinueOnError controls page-level recovery

Budgets enforced fail-closed before page mutation cover MaxPixelsPerPage and MaxTotalPixels pixels, MaxWordsPerPage and MaxTotalWords words, MaxWordCharacters characters per word, plus confidence and DPI

Example

var
  Options: TPdfOcrOptions;
  Report: TPdfOcrReport;
begin
  Options := TPdfOcrOptions.Default;
  Options.Dpi := 300;
  Options.MinConfidence := 0.75;
  if Pdf1.ApplyOcrSearchLayer(OcrProvider, Options, Report) then
    Pdf1.SaveAs('searchable.pdf');
end;

See Also

DetectPageSkew, GetStructuredText, Text