SaveDOCXToStream

Document conversion, extraction, DOCX, streams

Description

Converts a PDF page range into an editable WordprocessingML document and writes the DOCX package at the current stream position

Syntax

Function TPDFlib.SaveDOCXToStream(Const PageRange: WideString;
  Options: Integer; Target: TStream): Integer;

Parameters

PageRangeA one-based page range, or an empty string for every page; explicit page order is preserved
OptionsA bit mask: PDF_DOCX_INCLUDE_IMAGES = 1 embeds page images as floating PNG objects, PDF_DOCX_DETECT_HEADINGS = 2 maps large short lines to Heading 1 through Heading 3, PDF_DOCX_PRESERVE_STYLES = 4 retains font names, sizes, colours, bold, italic, superscript and subscript, and PDF_DOCX_PRESERVE_PAGE_BREAKS = 8 inserts editable page breaks; PDF_DOCX_DEFAULT enables all four
TargetThe destination stream, which does not become owned by the library

Return values

Returns the number of converted pages, or zero when validation, cancellation, extraction, packaging, or writing fails

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 keeps extracted text in mixed or geometric fallback, and unknown custom roles are not guessed from their names

Reading-order paragraphs, bullet and numbered lists and tables become native editable Word content rather than page snapshots

Empty tagged cells, horizontal spans and vertical spans use native Word table cells, w:gridSpan and w:vMerge

Joined table fragments remain in one w:tbl across pages and identified repeated continuation headers are omitted; the page-break option inserts an editable break in the continued table

Geometric columns, margin furniture, continuation matching and opt-in inferred merges remain heuristic; inspect the latest diagnostics and structured JSON provenance when fidelity matters

Selected page models and included images are retained for document-wide analysis; XML and package assembly use additional buffers, so memory grows with the selected content and images

The output is a deterministic DOCX ZIP package with CRC-checked raw Deflate entries and requires no Office installation

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

LastErrorCode is 114 for invalid arguments and 518 for extraction, packaging, or stream failures

See also

SaveDOCXToFile, ExtractStructuredDocument, ExportDocumentHTML