HeadlinesBriefing favicon HeadlinesBriefing.com

Convert HTML to Word with dom-docx

Hacker News •
×

dom‑docx converts semantic HTML fragments to native, editable Word documents (OOXML). It supports paragraphs, runs, lists, tables, and images without screenshots or layout hacks. A live demo is at dom-docx.com.

The library runs on Node.js ≥20 and can operate without a browser or Playwright for the default inline style source. When stylesheets or class selectors are needed, Playwright + Chromium can be installed separately. The tool uses a visual regression loop: render HTML in Chromium, convert to DOCX, rasterize with LibreOffice, and score layout fidelity.

Usage is simple: `npx dom-docx input.html -o output.docx` or via API `convertHtmlToDocx(html, options)`. Options allow page size, orientation, margins, fonts, metadata, headers, footers, page numbers, and even a cover page or table of contents. Images are embedded automatically; remote images require a resolver.

The browser bundle lets you convert directly in the user’s tab, while the Node bundle supports headless rendering and optional rasterization of complex SVG or canvas elements. Overall, dom‑docx offers a quick, code‑free path to high‑fidelity Word documents from HTML.