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

Requires the Small Business or Enterprise edition: add FPdfSmallBusiness to a uses clause (with Lib\SmallBusiness on the search path); otherwise the method raises EPdfSmallBusinessRequired

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

TPdfOcrOptions is the options record ApplyOcrSearchLayer receives; TPdfOcrOptions.Default starts from 300 DPI, a 0.5 confidence floor, an Arial invisible text layer font, SkipPagesWithText and ContinueOnError enabled, and the pixel, word, and per-word character budgets listed below

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

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

Since v3.275.0, cached Unicode fonts encode whole characters through their CID maps, supplementary-plane characters included; FontName must select a Unicode font whose cached cmap covers the requested text, such as a suitable symbol font for supplementary symbols

Supplementary insertion needs the native custom CID font and charcode APIs; missing mappings or required APIs, NUL and unpaired UTF-16 units fail explicitly, and every new word on the failed or cancelled page is removed

Completed pages follow the existing page-level recovery policy; publish saved source bytes only after checking the overall report, then bind a new semantic review to those exact saved bytes before requesting tagged output

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