PDFium Delphi Component Docs

Optional Tesseract OCR backend

CreatePdfTesseractOcrProvider supplies ApplyOcrSearchLayer with an IPdfOcrProvider; installing Tesseract and traineddata is optional and external

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

If dependencies fail, TryCreatePdfTesseractOcrProvider returns details in ErrorMessage with a nil Provider, without altering the process search path

Recognition calls use separate native API instances, composite BGRA alpha over white and decode UTF-8; words are returned as quadrilaterals relative to the image's top-left, with confidence normalised to 0–1

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

Recognition checks cancellation and its deadline; native model initialisation has no cancellation callback, so the allowance is checked just before and after initialisation

Failed calls throw away partial output, and cancellation retains EPdfOperationCancelled; incomplete searchable text is never added silently

ABI fixtures cover Delphi and FPC Win32/Win64; both compilers' Win64 tests also verify real Tesseract 5.5 recognition, searchable-layer saving and reopening, and unchanged rendered output

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;