GetPageText

Extraction, Page manipulation

Description

This function provides two different methods for extracting text from the selected page, and presents the results in a variety of formats

The SetTextExtractionWordGap, SetTextExtractionOptions and SetTextExtractionArea

functions can be used to adjust the text extraction process

Unicode extraction resolves verified ToUnicode inheritance from embedded base streams and the bundled Adobe ToUnicode resources, including child overrides, ligatures, and supplementary Unicode targets. Unsupported bases do not authorize guessed mappings; see Unicode CMap Resources

Syntax

Delphi

Function TPDFlib.GetPageText(ExtractOptions: Integer): WideString;

ActiveX

Function PDFlib::GetPageText(ExtractOptions As Long) As String

DLL

const wchar_t* DLGetPageText(int InstanceID, int ExtractOptions);
const char* DLGetPageTextA(int InstanceID, int ExtractOptions);

Parameters

ExtractOptionsUsing the standard text extraction algorithm: 0 = Extract text in human readable format 1 = Deprecated 2 = Return a CSV string including font, color, size and position of each piece of text on the page Using the more accurate but slower text extraction algorithm: 3 = Return a CSV string for each piece of text on the page with the following format: Font Name, Text Color, Text Size, X1, Y1, X2, Y2, X3, Y3, X4, Y4, Text The co-ordinates are the four points bounding the text, measured using the units set with the SetMeasurementUnits function and the origin set with the SetOrigin function. Co-ordinate order is anti-clockwise with the bottom left corner first. 4 = Similar to option 3, but individual words are returned, making searching for words easier 5 = Similar to option 3 but character widths are output after each block of text 6 = Similar to option 4 but character widths are output after each line of text 7 = Extract text in human readable format with improved accuracy compared to option 0 8 = Similar output format as option 0 but using the more accurate algorithm. Returns unformatted lines. 9 = Extract text in visual reading order: a recursive XY-cut keeps multi-column layouts column by column instead of interleaving lines. 10 = Table-aware tab-separated export: block left edges cluster into global column positions so vertically aligned cells stay aligned across rows. 11 = Layout-preserving fixed-grid text: the page maps onto a monospace character grid padded with real spaces, keeping the visual alignment without tab stops.

Return values

The text of the selected page, or an empty string if a problem occurred. Lines are separated with CR-LF characters.

Encoding CMap decoding

Native extraction preserves one-to-four-byte character codes and their CID mappings, using complete source bytes for ToUnicode lookup and the declared WMode for text movement; see Encoding CMap decoding

Vertical composite text

Composite extraction with verified vertical WMode follows the column baseline and its DW2 and W2 advances, preserving source locations and reading order across text-showing operators. Horizontal scaling changes glyph width without scaling vertical cursor movement

Type3 text

Type3 extraction follows the horizontal component of FontMatrix-transformed widths, with character spacing, word spacing, text rise, and horizontal scaling applied in text space. Complete known Differences mappings preserve ligatures and supplementary characters without a ToUnicode stream, while Unicode status still records that ToUnicode is absent

Content strings retain their font-encoded bytes, including a leading FE FF sequence; see Type3 exact editing