Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.
npm install betterdocxEasily generate and modify .docx files with JS/TS. Works for Node and on the Browser.
A modern fork of docxjs
---
``bash`
npm install betterdocx
pnpm install betterdocx
bun install betterdocx
`typescript
import { Document, Packer, Paragraph, TextRun } from "betterdocx";
import * as fs from "fs";
const doc = new Document({
sections: [{
properties: {},
children: [
new Paragraph({
children: [
new TextRun("Hello World"),
new TextRun({
text: "Foo Bar",
bold: true,
}),
],
}),
],
}],
});
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});
``
Check the docs folder for comprehensive documentation including:
- Getting Started - Installation and basic usage
- Usage Guides - Detailed guides for all features
- Exporting - How to generate .docx files
- Modifying Documents - Working with existing files
- Utility Functions - Helper functions and utilities
Check the demo folder for examples.
Read the contribution guidelines to get started.
MIT