Files
docx/docs
Dolan 66743729ef feat(layout): measure Greek, Cyrillic, Vietnamese, Latin Extended, punctuation and symbols with Word's widths, and break lines after the spaces Word breaks after (#3628)
* test(layout): probe how wide Word draws the characters of the width tables, and how lines break after other spaces

* feat(layout): measure Latin Extended, Greek, Cyrillic, Vietnamese, punctuation and symbols with Word's widths, and break lines after the spaces Word breaks after

* chore(layout): spell the generator's tool names

* fix(layout): stop at a symbol whose character isn't four hexadecimal digits, rather than read part of it or throw

w:char is ST_ShortHexNumber, two bytes, but SymbolRun writes whatever string it is given. parseInt read "F0FCzz" as
F0FC, and a code past U+10FFFF, such as "110000", made String.fromCodePoint throw, which made Packer reject.

* docs(layout): give a mathematical symbol in Calibri as the example of a character whose width isn't known

Word's PDF showed its Cambria has Greek, so Greek in Cambria no longer stops the layout.
2026-10-02 02:01:00 +01:00
..
2020-09-05 18:40:40 +01:00
2020-09-05 18:51:50 +01:00

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);
});

clippy the assistant


Made with 💖