PDFium Delphi Component Docs

CharacterIndexToTextIndex method

Component: TPdf  ·  Unit: PDFium
Map a character index to its position in the string returned by Text

Syntax

function CharacterIndexToTextIndex(Index: Integer): Integer;

IndexInteger. Zero-based character index on the current page
ResultInteger. Zero-based offset of that character within the extracted text, or -1 when the character contributes nothing to it

Description

The character list and the extracted string are not the same sequence: generated characters such as inserted spaces and hyphens appear in one and not the other. This maps from the character list to the string

It is what turns a hit reported against character indexes - a search result, a click - into an offset a caller can use to slice the string from Text

A result of -1 means the character has no representation in the extracted text, which is normal for characters flagged by CharacterGenerated

See Also

TextIndexToCharacterIndex, Text, CharacterCount, CharacterGenerated