PDFium Delphi Component Docs

BuildSpokenTextFromWords function

Unit: PDFium
Constructs a TPdfSpokenText chunk from a contiguous TPdfWordBox range

Syntax

function BuildSpokenTextFromWords(const Words: TPdfWordBoxes; FirstWord, LastWord: Integer): TPdfSpokenText;

Parameters

WordsTPdfWordBoxes - Word boxes from a page or viewer
FirstWordInteger - First zero-based word index, clamped to 0
LastWordInteger - Last zero-based word index, clamped to High(Words)

Return Value

A TPdfSpokenText whose Text is ready for a speech engine and whose Spans map each word back to page text

Description

The helper traverses the selected TPdfWordBox range and appends each word with SpokenTextAppend

The resulting span table preserves each word's page number, source character index and source character count so a speech engine offset can be translated back to the PDF page

WordSegmentation defaults to wsmWhitespace, preserving the original space/tab/newline/NBSP tokenizer

Explicit wsmCjk provides deterministic tailored units: individual Han scalars, Hiragana runs, Katakana runs, Hangul runs, separate punctuation and script transitions, including fullwidth forms and Unicode whitespace

Recognised combining accents, voiced marks and variation selectors remain with the preceding unit; valid surrogate pairs are never split

This profile provides useful navigation units without a dictionary and is not linguistic Chinese/Japanese word recognition or full Unicode boundary-conformance; see Unicode text segmentation for the distinction between default boundaries and language-specific tailoring

Document, viewer and session modes are independent; change the applicable host before extracting or playing words

Viewer changes clear tracked/prefetched word geometry and the active cursor; session changes stop playback so the next chunk uses the selected mode

Native CJK word boxes include CharacterIndices, mapping each UTF-16 text unit to its native character index; StartIndex and Count remain native ranges, whilst pure BuildWordBoxes uses UTF-16 ranges

BuildSpokenTextFromWords preserves adjacent source units without inserting artificial spaces and emits exact source mappings from CharacterIndices; invalid explicit maps raise EPdfError

Remarks

Example

Words := Pdf1.PageWordBoxes;
Spoken := BuildSpokenTextFromWords(Words, 0, High(Words));

See Also

TPdf.PageWordBoxes, TPdfView.PageWordBoxes, SpokenToPageChar