DOCX
Generate native Word .docx files from JSON and TypeScript.
Install
Terminal
npm install @paperjsx/json-to-docx
Requires Node.js >=18.
Quick Start
TypeScript
import { renderToDocx } from "@paperjsx/json-to-docx";
import { writeFileSync } from "node:fs";
const result = await renderToDocx({
type: "DocxDocument",
pageSize: "a4",
pages: [
{
elements: [
{ type: "heading", level: 1, text: "Annual Report" },
{
type: "paragraph",
text: "Revenue grew 34% year over year, driven by enterprise expansion.",
},
{
type: "table",
rows: [
{ isHeader: true, cells: [{ text: "Region" }, { text: "Revenue" }] },
{ cells: [{ text: "North America" }, { text: "$5.1M" }] },
{ cells: [{ text: "Europe" }, { text: "$3.6M" }] },
],
},
],
},
],
});
writeFileSync("report.docx", result.buffer);
Core API
renderToDocx(input, options?)— render JSON to.docx; returns{ buffer }.validateDocxDocument(input)— validate against the Zod schema before rendering.hydrateDocx(templateBuffer, data, options?)— fill placeholders in a.docxtemplate.scanForPlaceholders(templateBuffer)— list placeholders in a template for inspection.renderHtmlToDocx(html, options?)— convert HTML to.docx.diffDocxDocuments(a, b)/compareDocuments(a, b)— structural diff.
Zod schemas (DocxDocumentSchema, DocxElementSchema, TableElementSchema, etc.) are exported for validation and AI-agent tooling.
Pro
@paperjsx/json-to-docx-pro adds advanced pagination, tracked changes, compare flows, DOCX-to-PDF conversion, and production/self-hosted commercial rights.
Terminal
npm install @paperjsx/json-to-docx-pro
Set PAPERJSX_LICENSE_KEY from your dashboard. See License & Pricing.