Converte DOCX para HTML no navegador. Usa jszip e fast-xml-parser internamente, com override opcional do ParserClass.
npm install docx-to-html-converterConvert .docx (Microsoft Word) documents directly to HTML in the browser.
Built on top of JSZip and fast-xml-parser, bundled as a standalone library or installable via npm.
---
- 📄 Parse DOCX files in the browser (no server required).
- 🖋️ Preserves styles: paragraphs, headings, lists, tables, inline formatting.
- 🎨 Extracts page size and margins as CSS @page rules (optional).
- 🖼️ Supports embedded images.
- 🔗 Handles hyperlinks (internal and external).
- 🔧 Available as:
- ESM/CJS package (for bundlers and Node.js).
- IIFE build (global window.DocxToHtmlConverter for CDN usage).
---
bash
npm install docx-to-html-converter
``js
import { DocxToHtmlConverter } from "docx-to-html-converter";// arrayBuffer from a File, fetch(), etc.
const buffer = await file.arrayBuffer();
const converter = await DocxToHtmlConverter.create(buffer);
const { html, pageStylesCss } = await converter.convert({
extractPageStyles: true,
});
document.body.innerHTML = html;
`$3
`html
`---
Demo
index.html in a browser.
You can drag & drop a .docx file and preview the converted HTML side by side.---
API
$3
Create a new converter from a DOCX ArrayBuffer.
Optionally pass a custom XML parser class (defaults to fast-xml-parser).$3
Convert the document to HTML.-
options.extractPageStyles (boolean, default: true)
Extracts @page CSS with margins and page size.Returns an object:
`ts
{
html: string; // HTML content
pageStyles?: object; // Page style object
pageStylesCss?: string // CSS string with @page
}
`---
Development
Build outputs:
-
dist/index.js → ESM
- dist/index.cjs → CommonJS
- dist/index.iife.js → Standalone browser build (global)`bash
build all targets
npm run buildclean dist/
npm run clean
``---
MIT © 2025 Your Name