PDFium Delphi Component Docs

Optional Tesseract OCR provider

CreatePdfTesseractOcrProvider supplies an IPdfOcrProvider for ApplyOcrSearchLayer; Tesseract and traineddata are optional external dependencies

Use an explicit absolute library path, a tessdata directory and the requested language identifiers, such as eng; the DLL architecture must match the process

TryCreatePdfTesseractOcrProvider returns dependency failures in ErrorMessage and leaves Provider nil without changing the process search path

Each recognition call owns a separate native API instance, composites BGRA alpha onto white, decodes UTF-8 text and returns word quadrilaterals in top-left image coordinates with confidence normalized to 0–1

Default selects page segmentation mode 3 and engine mode 3, a 60,000 ms deadline, 16,777,216 pixels, 100,000 words and 1,048,576 text characters

Recognition monitors cancellation and the deadline; model initialization has no native cancellation callback, so the budget is checked immediately before and after initialization

Failed calls discard partial output and cancellation preserves EPdfOperationCancelled; the API does not silently add incomplete searchable text

Delphi and FPC Win32/Win64 ABI fixtures are verified; real Tesseract 5.5 recognition, searchable-layer save/reopen and unchanged rendering are verified on Win64 in both compilers

ProviderOptions := TPdfTesseractOptions.Default;
Provider := CreatePdfTesseractOcrProvider(
  LibraryPath, TessdataDirectory, 'eng', ProviderOptions);
OcrOptions := TPdfOcrOptions.Default;
Pdf.ApplyOcrSearchLayer(Provider, OcrOptions, Report, CancellationToken);

Public declarations

type
  EPdfTesseractError = class(Exception);

  TPdfTesseractOptions = record
    // Tesseract PSM ordinals: 3 = automatic, 6 = block, 7 = single line
    PageSegmentationMode: Integer;
    // Tesseract OEM ordinals: 1 = LSTM, 3 = default
    EngineMode: Integer;
    TimeoutMilliseconds: Cardinal;
    MaxPixels: Int64;
    MaxWords: Integer;
    MaxTextCharacters: Integer;
    class function Default: TPdfTesseractOptions; static;
  end;

// Each recognition call owns a separate API instance; providers can be shared
// Libraries and traineddata remain optional, explicitly configured dependencies
function CreatePdfTesseractOcrProvider(const LibraryPath, TessdataDirectory,
  Languages: string; const Options: TPdfTesseractOptions): IPdfOcrProvider;

// Dependency errors are returned without changing the process search path
function TryCreatePdfTesseractOcrProvider(const LibraryPath, TessdataDirectory,
  Languages: string; const Options: TPdfTesseractOptions;
  out Provider: IPdfOcrProvider; out ErrorMessage: string): Boolean;