PDFium Delphi Component Docs

Text page snapshots

Component: TPdf  ·  Unit: PDFium
Capture a complete caller-owned view of one native text page in a bounded pass and reuse completed snapshots across text consumers

Types

TPdfTextSnapshotOptions = record ... end;

TPdfTextSnapshotStatus = record ... end;

TPdfTextCharacterSnapshot = record ... end;

TPdfTextCharacterSnapshots = array of TPdfTextCharacterSnapshot;

TPdfTextObjectSnapshot = record ... end;

TPdfTextObjectSnapshots = array of TPdfTextObjectSnapshot;

TPdfTextPageSnapshot = record ... end;

TPdfTextPageSnapshot owns its Text, Characters array, and normalised TextObjects array and never exposes a native page, text-page, font, or page-object handle

Characters is declared as TPdfTextCharacterSnapshots and TextObjects as TPdfTextObjectSnapshots, dynamic-array types that size themselves to the captured content and stay empty when the page carries no text

Each TPdfTextCharacterSnapshot carries the PDFium character Index, Unicode scalar, UTF-16 TextIndex and TextLength, the Generated and IsHyphen flags, mapping status through UnicodeMapError, strict and loose bounds, Origin and Angle with their HasOrigin and HasAngle flags, FontSize with HasFontSize, fill and stroke colour, alpha, matrix, and a snapshot-local TextObjectIndex

CodePoint holds the Unicode scalar PDFium mapped for the character, and HasUnicode is False when no mapping exists, in which case the page text substitutes U+FFFD and Status.UnmappedCharacterCount records the character

HasBounds is True only when the native query returned a strict character box, so Bounds is valid exactly when the flag is set

Each TPdfTextObjectSnapshot represents one distinct native text object and carries its FirstCharacterIndex, character count, font name and flags through HasFontInfo, FontWeight with HasFontWeight, and RenderMode with HasRenderMode

Every optional fact has a corresponding Has... flag so missing native metadata is distinct from a valid zero or empty value

Bounded read

function ReadTextPageSnapshot(PageNumber: Integer; const Options: TPdfTextSnapshotOptions; out Status: TPdfTextSnapshotStatus): TPdfTextPageSnapshot;

ReadTextPageSnapshot captures straight from the native text page under the render lock and never consults or fills the snapshot cache

PageNumber is one-based and reading a non-current page does not change TPdf.PageNumber

TPdfTextSnapshotOptions.Default permits 1,000,000 MaxCharacters, 100,000 MaxTextObjects, 16 MB of UTF-8 font-name buffers through MaxFontNameBytes, and no DeadlineMilliseconds

The status carries Completed, NativeCharacterCount, CharactersVisited, TextObjectsVisited, FontNameBytes, the unmapped and failure counters, and the CharacterLimitReached, TextObjectLimitReached, FontNameLimitReached, and DeadlineReached truncation flags

Status.Completed is False when the character, object, font-name, or deadline budget truncates the result

GeometryFailureCount and MetadataFailureCount count unavailable per-character or per-object facts without aborting the remaining traversal

The returned record repeats the same status in its Status field so queued processing can retain data and completion state together

Revision-aware cache

property TextPageSnapshot[PageNumber: Integer]: TPdfTextPageSnapshot;

property TextSnapshotCacheCapacity: Integer; // default 8

property TextSnapshotCacheCount: Integer;

property TextSnapshotCacheHitCount: Int64;

property TextSnapshotCacheMissCount: Int64;

The TextPageSnapshot indexed property applies default budgets and stores only completed snapshots in a bounded least-recently-used cache

Every return value is a deep copy, so changing a caller-owned string or array cannot modify the cached snapshot or the PDF

Page edits invalidate that page, while document replacement and page-tree changes clear the complete cache

TextSnapshotCacheCapacity defaults to 8, rejects negative values, and evicts the least-recently-used snapshot when a new entry would exceed it

TextSnapshotCacheCount reports how many page snapshots are currently retained

TextSnapshotCacheHitCount and TextSnapshotCacheMissCount accumulate over the component's lifetime so callers can measure how well the capacity matches their access pattern

A capacity of zero disables retention without disabling direct snapshot reads

GetStructuredText and physical-layout GetTextInReadingOrder reuse the same snapshot and use O(n log n) geometry sorting for layout order

Example

var
  Snapshot: TPdfTextPageSnapshot;
  Character: TPdfTextCharacterSnapshot;
begin
  Pdf.TextSnapshotCacheCapacity := 16;
  Snapshot := Pdf.TextPageSnapshot[1];
  if not Snapshot.Status.Completed then
    raise Exception.Create('Text snapshot is incomplete');

  for Character in Snapshot.Characters do
    if Character.HasBounds and Character.HasUnicode then
      IndexCharacter(Character.CodePoint, Character.Bounds);
end;

See Also

GetStructuredText, GetTextInReadingOrder, Structure traversal