Paged.The open publishing system
The technical handbook
Module commands

Paged Docs / Module commands

paged.doc commands

paged.doc's objects and typed commands — a Word document's blocks, table cells, runs and merge fields as writable objects, placing and exporting .docx, and a .docx opened on its own headless.

Tier: IntermediateIntermediateIIreferenceDraft

Reviewed against engine v0.74.2

Change a Word document's text, cell by cell, and save it back as Word.

In short paged.doc exposes a Word document as objects a script, an extension or the command line reads and writes, and three typed commands, media.paged.doc.command.<name>. Every write changes the poured text on the page and is patched into the .docx on export, so what you did not touch stays as Word wrote it. How to call them: Module commands.

Opening a .docx on its own

The Node command line opens a .docx as a document of its own, a page per section, as the editor's File ▸ Open does: paged.doc's importer opens it through the SDK headless host's native-document door. Writing -o x.docx exports through the module, so the edits are in the Word file:

paged-node set price-table.docx plugin:media.paged.doc/block/docx_f0/b1/c2/p0 text Pears \
  -o edited.docx --plugins=@paged-media/doc

Addresses

The document opened on its own has the frame docx_f0; a placed one, its frame's id.

AddressWhat
plugin:media.paged.doc/docxDocument/<frame>The document.
…/block/<frame>/b<i>A paragraph or a table, by index.
…/block/<frame>/b<i>/c<k>/p<m>Paragraph m of cell k of table b<i>.
…/run/<frame>/b<i>/r<j>, …/run/<frame>/b<i>/c<k>/p<m>/r<j>A run, in the body or in a cell.
…/mergeField/<frame>/b<i>/f<o>The o-th merge field of a block.

What is writable

Each write is one undo step.

PropertyMeaning
block.textA paragraph's text, in the body or in a table cell. The first run takes the text and keeps its look; the other runs are emptied.
block.listItemsA list's items as text[]: the first items take the new texts, the rest are removed, and extra items copy the last one.
run.textA run's text, in the body or in a cell.
mergeField.valueA merge field's result, in the body or a cell; the field code stays, so the file still merges in Word.

Run formatting is not a writable property here. In the editor, formatting made on the canvas — a word made bold, a character style on part of a run, a size or colour from the document's swatches — is saved back on export: the Word run is split, the changed piece gets only the properties that changed, and runs nobody touched stay byte-identical. Edits typed into a table cell — paragraphs added or removed included — are saved back too, and a placed document's tables are found again by their content after the text around them changed.

Typed commands

CommandArgumentsResult
placeDocbytes (a .docx), fileName{ document, frame, story } — placed into a frame of the current document.
exportDocxdocument{ bytes, fileName } — the .docx with every edit patched in.
fillMergeFieldsdocument, values (field name → text){ filled, unknown } — one undo step; filled counts field instances.
paged-node invoke letter.docx media.paged.doc.command.fillMergeFields \
  '{"document":"plugin:media.paged.doc/docxDocument/docx_f0","values":{"City":"London","OrderNo":"A-17"}}' \
  -o letter-filled.docx --plugins=@paged-media/doc

paged-node invoke letter.paged media.paged.doc.command.exportDocx \
  '{"document":"plugin:media.paged.doc/docxDocument/docx_f0"}' \
  --result-out letter.docx --no-save --plugins=@paged-media/doc

Template fields

paged.doc's field kinds — media.paged.doc.blockText, media.paged.doc.listItems and media.paged.doc.mergeField — find their paragraph by an anchor:

{ "bookmark": "intro" }
{ "style": "Heading1", "occurrence": 0 }
{ "heading": 2, "occurrence": 0 }
{ "block": 3 }
{ "block": 1, "cell": 2, "paragraph": 0 }

heading is the n-th paragraph in Word's "heading n" style or one based on it; occurrence is 0-based. A bookmark or style anchor finds paragraphs inside table cells too, and { block, cell, paragraph } names one directly.

Limits

Headers, footers and footnotes are read but not placed on the page; tracked changes and floating images are reported, not placed.

On this page