mirror of
https://github.com/dolanmiu/docx.git
synced 2026-11-30 16:47:55 +01:00
Word's PDFs of round 26 settled what word-stops-compat3, word-stops-top-spacing3 and -4, word-stops-booklet3, word-stops-divisions2 and word-stops-fe-layout3 probed. In Word 2010's and 2007's modes a table of a share of the width is that share of the text and its margins, a table widened for a long word grows to the room with the margins, floating tables sized to their text shift as CN9's did, text after a tab past the end goes on to 22 inches, and gaps of 1250 twips or less beside a frame are left empty; in Word 2007's mode East Asian text in its language breaks as in none and VML shapes' outlines take no room. suppressTopSpacing leaves 0.8 lines and bordered paragraphs' later lines as they are, reverse-folded booklets are the section's pages, a division's box is drawn once with its later paragraphs taking its margins and side borders, and useFELayout puts half the font's average character width between East Asian text and Latin letters or digits.
Welcome to docx
What is docx?
docx is a TypeScript/JavaScript library for generating Word documents (.docx files) programmatically. It provides a declarative API that works seamlessly in both Node.js and browser environments.
Why docx?
- Declarative API - Define what you want (objects/config), not how to build it step-by-step
- TypeScript First - Full type definitions with IntelliSense support
- Universal - Works in Node.js, browsers, and serverless environments
- No Dependencies - Zero external runtime dependencies
- Full Featured - Tables, images, shapes, charts, headers, footers, styles, and more
Quick Navigation
| I want to... | Go to... |
|---|---|
| Get started quickly | Quickstart Guide |
| Learn a specific feature | Usage Guides |
| See working examples | Demo Files |
| Browse the API | API Documentation |
| Modify existing documents | Patcher |
Installation
npm install --save docx
Then you can require or import as usual:
const docx = require("docx");
import * as docx from "docx";
// or
import { Document, Packer, Paragraph, TextRun } from "docx";
Shapes, watermarks and charts come with the package too, from docx/shapes, docx/watermarks and docx/charts:
import { ShapeRun } from "docx/shapes";
import { TextWatermark } from "docx/watermarks";
import { ChartRun } from "docx/charts";
Basic Usage
import * as fs from "fs";
import { Document, Packer, Paragraph, TextRun } from "docx";
const doc = new Document({
sections: [
{
children: [
new Paragraph({
children: [
new TextRun("Hello World"),
new TextRun({
text: " - Bold text",
bold: true,
}),
],
}),
],
},
],
});
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});
Made with 💖
