DOCX creation, editing, and analysis
Overview
A .docx file is a ZIP archive containing XML files.
Task Quick Start
| Task | Approach |
|---|---|
| Analyze content | pandoc document.docx -o output.md |
| Convert .doc | python scripts/office/soffice.py --convert-to docx document.doc |
| Create new doc | Use docx-js. See references/creating.md |
| Edit existing doc | Unpack → edit XML → repack. See references/editing.md |
| Clean changes | python scripts/accept_changes.py input.docx output.docx |
| Convert to PDF | python scripts/office/soffice.py --convert-to pdf document.docx |
Reference Materials
To ensure high-quality document manipulation, refer to these detailed guides:
- Creating Documents: references/creating.md - Full guide for
docx-js(JavaScript). - Editing Documents: references/editing.md - Detailed workflow for unpacking and editing XML directly.
- XML Reference: references/editing.md#xml-reference - Patterns for tracked changes, comments, and images.
Critical Rules
For docx-js (Creating)
- Set page size explicitly - Defaults to A4; use US Letter (12240 x 15840 DXA) for US documents.
- Tables need dual widths -
columnWidthsarray AND cellwidth, both must match in DXA. - Never use
\nor unicode bullets - Use separate Paragraphs andLevelFormat.BULLET.
For XML Editing (Modifying)
- Author Identity: Use "Claude" for tracked changes and comments.
- Minimal edits - Only mark what actually changes in the XML.
- Comment Markers: Siblings of
<w:r>, never inside.
Dependencies
- pandoc: Text extraction
- docx:
npm install -g docx(new documents) - LibreOffice: PDF conversion (
scripts/office/soffice.py) - Poppler:
pdftoppmfor images