Professional Word document engineering — create, edit, and analyze .docx files.
A comprehensive reference for generating Word documents programmatically, editing existing documents via XML, and mastering OOXML features like tracked changes, comments, tables, images, and multi-column layouts.
Generate .docx files with the docx (npm) library:
- Page setup (US Letter, A4, landscape)
- Table of contents
- Headers, footers, page numbers
- Tables with proper DXA-based sizing
- Bullet and numbered lists
- Images, hyperlinks, bookmarks
- Footnotes, tab stops, multi-column layouts
- 15+ critical gotchas documented from real-world usage
Modify existing .docx files through XML:
- Unpack → edit XML → repack workflow
- Smart quotes for professional typography
- Full OOXML element reference
Complete XML patterns for:
- Insertions and deletions
- Paragraph-level deletion marking
- Rejecting another author's changes
- Restoring deleted content
- Comments and threaded replies
npm install -g docxCreate a document:
const { Document, Packer, Paragraph, TextRun } = require('docx');
const fs = require('fs');
const doc = new Document({
sections: [{
children: [
new Paragraph({ text: "Hello, World!" }),
]
}]
});
Packer.toBuffer(doc).then(buffer => {
fs.writeFileSync("hello.docx", buffer);
});| You want to... | Use |
|---|---|
| Create a new document from scratch | docx (npm) library |
| Edit text in an existing document | Unpack → XML Edit → Repack |
| Review or accept tracked changes | pandoc --track-changes=accept |
| Extract content for analysis | pandoc -t markdown |
| Add complex tracked changes | Direct XML manipulation |
| Insert comments | XML comment markers |
- Node.js —
docxpackage (npm) - pandoc — document reading/conversion
- LibreOffice — format bridging, PDF output
- Poppler —
pdftoppmfor page rendering
npx skills add Jorgut/docx-forgeMIT — feel free to use, modify, and distribute.