Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@office-open/docx

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@office-open/docx

Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.

Source
npmnpm
Version
0.6.7
Version published
Weekly downloads
693
-59.83%
Maintainers
1
Weekly downloads
 
Created
Source

@office-open/docx

npm version npm downloads npm license

Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.

Features

  • 📄 Document Generation — Create Word documents with sections, headers, footers, and page numbers
  • ✍️ Paragraphs & Text — Rich text support with bold, italic, underline, strikethrough, and more
  • 📊 Tables — Full table support with merged cells, borders, and styles
  • 🖼️ Images — Inline and floating images with sizing, positioning, and wrapping
  • 🔗 Hyperlinks — External and internal hyperlinks with custom styling
  • 📑 Headers & Footers — First, last, even/odd page headers and footers
  • 📋 Lists — Numbered and bulleted lists with multiple levels and custom formats
  • 🎨 Styles — Paragraph, character, and table styles with inheritance
  • 📖 Table of Contents — Auto-generated table of contents with custom styling
  • 📝 Footnotes & Endnotes — Comprehensive footnote and endnote support
  • 📈 Charts — Bar, line, pie, area, and scatter charts with customization
  • 🔢 Math Equations — Full mathematical equation support via MathML
  • 🧩 SmartArt — Built-in SmartArt graphic generation
  • 📚 Bibliography — Source management and citation support
  • 💬 Comments — Document comments with author and date tracking
  • 📝 Track Revisions — Insertions, deletions, and formatting changes
  • 📋 Content Controls — Structured document tags (SDT) for form-like documents
  • 📦 Text Boxes — Floating text boxes with content and styling
  • ☑️ Checkboxes — Form checkbox support in documents
  • 🖌️ DrawingML — Shapes with fills, shadows, effects, and transformations
  • 🔤 Custom Fonts — Font embedding and custom font tables
  • 🔧 Template Patching — Patch existing DOCX templates via placeholder replacement
  • ⚙️ Settings — Comprehensive document settings and compatibility options

Installation

# Install with npm
$ npm install @office-open/docx

# Install with pnpm
$ pnpm add @office-open/docx

Quick Start

import { Document, Paragraph, TextRun, Packer } from "@office-open/docx";
import { writeFileSync } from "node:fs";

const doc = new Document({
  sections: [
    {
      children: [
        new Paragraph({
          children: [
            new TextRun("Hello World"),
            new TextRun({
              text: " - Bold text",
              bold: true,
            }),
          ],
        }),
      ],
    },
  ],
});

const buffer = await Packer.toBuffer(doc);
writeFileSync("My Document.docx", buffer);

Examples

Check the demo folder for 100+ working examples covering every feature.

Benchmark

Performance comparison against original docx (9.6.1) package (higher ops/s is better, Windows 11 / Node 24).

DEFLATE = compressed (default), STORE = no compression. Both libraries use DEFLATE.

Create + toBuffer (end-to-end)

ScenarioDEFLATE syncSTORE syncDEFLATE asyncSTORE asyncdocx
Simple (2 paragraphs)300 ops/s2,370 ops/s367 ops/s2,577 ops/s153 ops/s
Styled paragraphs (20)449 ops/s2,145 ops/s520 ops/s2,047 ops/s208 ops/s
Table (10×5)522 ops/s1,850 ops/s451 ops/s1,818 ops/s196 ops/s
Full featured (header/footer/headings/table/paragraphs)382 ops/s1,099 ops/s384 ops/s1,054 ops/s168 ops/s

Large Files — Create + toBuffer

ScenarioDEFLATE syncSTORE syncDEFLATE asyncSTORE asyncdocx
2000 paragraphs43.3 ops/s62.7 ops/s19.8 ops/s64.9 ops/s24.2 ops/s
200×10 table85.5 ops/s107.0 ops/s23.0 ops/s110.7 ops/s34.3 ops/s
20 sections × 100 paragraphs47.9 ops/s73.7 ops/s20.4 ops/s76.3 ops/s20.4 ops/s

Large File (~100MB) — Mixed Content

2000 paragraphs + 200 unique images (500KB each) + 100×10 table. Speedup is vs docx.

MethodSpeedSpeedup
DEFLATE sync0.34 ops/s1.1x
STORE sync0.34 ops/s1.1x
DEFLATE async0.38 ops/s1.2x
STORE async0.38 ops/s1.2x
docx0.31 ops/s

License

Keywords

clippy

FAQs

Package last updated on 30 May 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts