PDFiumPas Docs

TryGetCharacterSource method

Component: TPdf · Unit: PDFium

Added in internal v3.399.0, updated 2026-11-10

Syntax

function TryGetCharacterSource(Index: Integer;
  out Info: TPdfCharacterSourceInfo): Boolean;

Reads the source of a zero-based native character index on the current page through an optional native extension

The bundled Win32 and Win64 ordinary and V8/XFA DLLs provide this local extension since internal v3.401.0 Other native builds return false unless they export both FPDFText_GetCharSourceInfo and FPDFTextObj_GetCharcodes with the ABI described in the repository's Tests/NativeTextSource/README.en-us.md Ordinary text extraction remains available when the extension is absent

False also means a closed page, invalid index or inconsistent source metadata On false, flags and charcode are zero, glyph and ActualText offset are minus one, handles are null and the path is empty Failure to load the native text page can raise EPdfError, as with other text queries

Source record

FieldMeaning
Flags1 for an original glyph, 2 for ActualText, 4 for a generated character, or 0 when no precise source is available
CharcodeOriginal raw code for glyph sources, before ToUnicode expansion, normalization or bidi ordering; this is distinct from TPdf.Charcode, which returns a UTF-16 character
GlyphIndexZero-based item ordinal inside the originating text object, or minus one for nonglyph sources
ActualTextOffsetOriginal zero-based UTF-16 offset in the declaring mark, or minus one for other sources
ActualTextMarkBorrowed handle of the exact ActualText declaration, or null
TextObjectBorrowed text object verified against the native character owner, or null when no precise source is available
ObjectPathRoot page object index followed by Form child indices, including inactive slots; at most 64 entries, with independently verified object kinds and bounds

One glyph can produce several extracted characters with the same ordinal ActualText reports logical declaration offsets without inventing a glyph association A generated character can return true with flag 4 and an empty source path True means the query succeeded and its metadata was checked; inspect the flag before using the source fields

All handles are borrowed and all indices describe the current live page Discard the record after editing, regenerating, closing or reloading that page, then query again Direct native mutations require the caller to reload the text page through the normal page lifecycle

For saved paragraph cluster association, use ReadPdfParagraphNativeMap or ReadPdfVerticalNativeMap, added in internal v3.400.0 These source and cluster queries do not authenticate externally changed glyph streams The extension does not add inheritance of ActualText declared only on an outer Form, and paths deeper than 64 remain unavailable

See also

CharacterInfo, CharacterCount, Paragraph editing and saved cluster maps