Docs / Guides

Markdown

Word documents

Open a .docx as pages, edit it with commands, save it back.

Open and convert

PdfDocument.open(bytes) accepts a .docx too and lays it out into PDF pages, so every viewing and annotation feature works on it. To edit the document itself, use WordDocument.

Edit with commands

const word = WordDocument.open(bytes);let state = word.command({ cmd: 'click', page: 0, x: 72, y: 700 });state = word.command({ cmd: 'insert', text: 'Approved by the board. ' });state = word.command({ cmd: 'key', key: 'Home', shift: true });state = word.command({ cmd: 'format', bold: 'toggle', color: '#1f3864' });const pages = word.pdf();     // the pages as they are nowconst docx = word.save();     // the edited .docx
CommandDoes
click, drag, keyPlace the caret, select, move with the keyboard ({ key, shift, ctrl })
insertType text
formatBold, italic, underline, strike, superscript, subscript, size, font, colour, highlight
paragraphAlignment, style, line spacing, lists (bullet, number, none), indent
insertTable, tableInsert a table; add or delete rows and columns, delete the table
insertImage, imageSizeAdd a picture; resize the selected one
undo, redo, selectAll, copy, cut, styles, stateThe usual editing commands

Every command returns the new state: caret and selection, the formatting at the caret, the current table or picture, which part is being edited (body, header, footer, footnote) and which pages changed.

What is supported

  • Styles, themes, sections, columns, lists and numbering.
  • Tables with merges, borders, shading, repeated header rows and rows split across pages.
  • Pictures inline or floating with text wrapping; shapes, text boxes, charts, SmartArt, EMF and WMF pictures.
  • Headers, footers, footnotes, fields and equations.
  • Complex scripts and right-to-left text.