Files
docx/docs
Dolan 28defb1aac feat(layout): keep text at least half a point from a floating table, and draw the characters a run's hint moves to its East Asian font in it, as Word does (#3724)
Word's PDFs of round 26 showed the text beside a table that text flows around 0 to 10 twips from it starting where it does with no distance, and 15 twips as given (word-stops-float-distance.docx FD1a to FD1f); curly quotes, dashes, an ellipsis, a degree sign and the like in the East Asian font of a run with the hint for East Asian text, in Chinese, Japanese and English (word-stops-run-fonts.docx HA1a to HA1c); accented letters in the high ANSI font given alone or beside Courier New (HA2a, HA2b); the scripts the run-font rules leave out in the high ANSI font, or in the fonts Word falls back on from either (HA3a); and Hebrew and Arabic in the font for ASCII (HA3b). The layout follows each, and stops in a run with the hint only where the PDFs don't settle the font: an East Asian font that isn't one, Latin Extended letters outside Chinese, a combining mark, a right-to-left run, and a block the rules leave out in a run whose two fonts differ.
2026-10-06 20:14:03 +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 💖