ExtractStructuredPage

Text, extraction, structured data

Description

Captures one PDF page and serializes its structured text model as schema 2 JSON, semantic XHTML, or table CSV

The model combines real structure-tree order and attributes with explicit geometric fallback, paragraphs, styled spans, inline hyperlink targets (<a href="...">), embedded PNG Data URI images (<img src="data:image/png;base64,..."/> in XHTML), and tables with empty or merged cells

Syntax

Delphi

Function TPDFlib.ExtractStructuredPage(Page, Format,
  Options: Integer): WideString;

ActiveX

Function PDFlib::ExtractStructuredPage(Page As Long, Format As Long, Options As Long) As String

DLL

const wchar_t* DLExtractStructuredPage(int InstanceID, int Page, int Format, int Options);
const char* DLExtractStructuredPageA(int InstanceID, int Page, int Format, int Options);

Parameters

PageThe one-based page number
FormatPDF_STRUCTURED_TEXT_JSON (0), PDF_STRUCTURED_TEXT_XHTML (1), or PDF_STRUCTURED_TEXT_CSV (2)
OptionsZero or PDF_STRUCTURED_TEXT_INCLUDE_STYLES (1) to include font, size, color, and vertical alignment in JSON and XHTML

JSON hierarchy

{
  "version": 2,
  "page": 1,
  "width": 612,
  "height": 792,
  "readingOrderSource": "tagged",
  "structureComplete": true,
  "warnings": [],
  "blocks": [
    {
      "type": "paragraph",
      "nodeId": 3,
      "source": "tagged",
      "confidence": 1,
      "furniture": "none",
      "furnitureSource": "",
      "bbox": [
        40,
        50,
        300,
        70
      ],
      "text": "Example paragraph",
      "lines": [
        {
          "spans": []
        }
      ]
    }
  ],
  "semantics": []
}

Page metadata includes readingOrderSource, structureComplete, and warnings; reading sources are tagged, mixed, geometric, or geometric-columns

Blocks include nodeId, source, confidence, furniture, furnitureSource, and bbox; spans retain originalText, contentEvent, nodeId, and artifact alongside output text

Table metadata includes logicalTable, logicalTableId, fragment, and continuation flags; rows carry logicalRow and repeatedHeader

Each cell records rowSpan, columnSpan, anchorRow, anchorColumn, covered, header, mergeSource, and confidence; empty tagged cells are retained and unknown cell bounds are null

The semantics array preserves the ordered full-tree begin, content, and end events, stable node and parent IDs, resolved and raw roles, namespaces, language, alternate text, ActualText presence, cell attributes, and page, stream, MCID, or object references

structureComplete describes traversal and content-binding coverage; it is not a tagging or accessibility certification

Return values

JSON and XHTML return complete standalone documents; XHTML represents merged cells with table spans and exposes block source metadata

CSV returns table cells only and is empty when the page has no table; merged cells put text in the anchor cell and leave covered cells empty

An invalid request or extraction failure returns an empty string

Remarks

Analysis uses SetStructuredTextOptions independently of the format-specific Options; inspect GetLastStructuredTextDiagnostics for reading sources and fallback warnings

Real tag-tree order takes precedence when content bindings are complete; unresolved or ambiguous content retains extracted text in mixed or geometric fallback, and unknown custom roles are not guessed from their names

Marked-content bindings distinguish page streams and nested Form XObject invocation routes; shared tagged Form occurrences with ambiguous semantic order are disclosed instead of assigned invented order

ActualText replacements preserve source text in JSON spans; object references are retained as semantic metadata, without extracting annotation text from them

Geometric table detection requires aligned multi-cell rows; optional merge inference and column detection remain heuristics

Bounding boxes use top-left page coordinates in PDF points; a fragment can retain its full source text-run bounds

Extraction preserves the selected page and open writer tag stack; current unsaved writer tags are included without closing tags or finalizing the document

DLL return pointers remain valid until the next string-returning call on the same instance

LastErrorCode is 111 for invalid page, format, or options and 515 when extraction fails

See also

ExtractStructuredDocument, ExtractPageTextBlocks, GetPageText