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| Command | Does |
|---|---|
click, drag, key | Place the caret, select, move with the keyboard ({ key, shift, ctrl }) |
insert | Type text |
format | Bold, italic, underline, strike, superscript, subscript, size, font, colour, highlight |
paragraph | Alignment, style, line spacing, lists (bullet, number, none), indent |
insertTable, table | Insert a table; add or delete rows and columns, delete the table |
insertImage, imageSize | Add a picture; resize the selected one |
undo, redo, selectAll, copy, cut, styles, state | The 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.