| Category | Text extraction |
|---|---|
| Note | Flags is accepted but unused — see Remarks |
Purpose — Extract the visible text of one page, either from the document currently being built or from an open import source, as a single Unicode string with best-effort reading-order assembly.
Description — dual-mode, real Unicode-aware decoding. Two independent code paths, chosen automatically:
- Output-side (
GetPageContentBytessucceeds —PageNumrefers to a page of the document you're building): decodes each text-showing run throughDecodeGIDString, the same font tables the engine used to write the glyphs — always accurate for output the engine itself produced. - Import-side (falls back to
GetImportPageContentDecodedwhen the page isn't one of the output document's own): a considerably richer decoder — resolves each font's/ToUnicodeCMap when present; for CJK Type0 fonts without/ToUnicode, resolves the encoding CMap (or treats codes as Identity 2-byte CIDs) and maps CID→Unicode via the embedded AdobeAdobe-<Ordering>-UCS2CMaps (GB1/CNS1/Japan1/Korea1); for simple fonts with/Encoding /Differencesand no/ToUnicode, maps overridden codes via glyph name → Adobe Glyph List, falling back to WinAnsi for non-overridden codes; recurses into Form XObjects (Do) so text inside them is included. When the imported page has a/Rotateof 90/180/270, extracted run coordinates are corrected to match the visual (rotated) orientation before area filtering, soAreaand the resulting reading order are consistent with what a viewer displays.
Runs are assembled into text via RunsToText, which inserts spaces based on the horizontal-gap threshold set by pdfSetTextExtractionWordGap and a fixed line-break heuristic (vertical gap 0.5).
Declarations
BOOL32 __stdcall pdfExtractText(PPDF IPDF, uint32_t PageNum, TTextExtractionFlags Flags, PFltRect Area, const wchar_t* Text, uint32_t* TextLen);
function pdfExtractText(const IPDF: PPDF; PageNum: Cardinal; Flags: TTextExtractionFlags; const Area: PFltRect; var Text: PWideChar; var TextLen: Cardinal): LongBool; stdcall; external 'LumasPdf.dll';
TTextExtractionFlags (from Lumas.Pdf.Types, bit values; accepted for ABI shape but not read anywhere in this call's implementation — see Remarks):
TTextExtractionFlags = Integer;
const tefDefault = 0; tefSortTextX = 1; tefSortTextY = 2; tefSortTextXY = 3;
tefDeleteOverlappingText = 4; tefNoHeuristic = 8;
TFltRect:
TFltRect = record Left, Bottom, Right, Top: Single; end;
Parameters
| Parameter | Type | Description |
|---|---|---|
IPDF | PPDF | Instance handle. |
PageNum | Cardinal | 1-based page number. |
Flags | TTextExtractionFlags | Accepted for ABI compatibility; has no effect — see Remarks. |
Area | PFltRect | Optional filter rectangle, or NULL for the whole page. Runs are kept only if their origin point (X, Y) falls inside [Left, Right] × [Bottom, Top] — this is a point-containment test on the run's start, not a bounding-box intersection, so a run that starts just outside Area but visually overlaps it is entirely excluded, and a run that starts inside but extends far past the edge is entirely kept. |
Text | PWideChar* | Receives the extracted text. |
TextLen | Cardinal* | Receives the character count. |
Return value — TRUE on success; FALSE if the handle is invalid or PageNum resolves to no content on either the output or import side.
Memory & buffers — Text points at an engine-owned buffer (ExtractTextBufPtr) valid until the next text-extraction call on this instance.
Remarks — compatibility parameters. Flags is accepted to match the reference ABI shape but is not consulted anywhere in this function's implementation — sort order (tefSortTextX/Y/XY), overlap deletion, and heuristic suppression are not selectable through this call regardless of what you pass. pdfSplitPageText and pdfGetTextBlockAsString are both thin wrappers over this function (with Flags=0, Area=nil), splitting the result on #10 — so "blocks"/"split lines" from those two calls are exactly the same reading-order lines this function produces, not a separate layout/paragraph analysis.
See also — pdfSplitPageText, pdfGetTextBlockAsString, pdfSetTextExtractionWordGap
C# (P/Invoke)
[return: MarshalAs(UnmanagedType.Bool)]
Core
pdfExtractText
The …A form takes UTF-8, …W
takes UTF-16; a bare name aliases the ANSI form.
Worked examples — complete programs in ten languages.