Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
Converts HTML documents to DOCX in the browser
html-docx-js is a lightweight JavaScript library that converts HTML documents into DOCX format for Microsoft Word 2007 and later, running entirely in the browser or Node.js.
html-docx-js is a small library by Evidence Prime, Inc. that takes a complete HTML document (as a string) and produces a Blob (or Buffer in Node.js) containing a .docx file. It performs the conversion client-side by exploiting Microsoft Word's altchunks feature, embedding the HTML inside an MHT document that Word converts to Word Processing ML when opened. The library is distributed under the MIT license and is available as a UMD module.
asBlob method accepts an options object for orientation (landscape or portrait) and a margins map with top, right, bottom, left, header, footer, and gutter values in twentieths of a point (defaults: 1440 for main margins, 720 for header/footer, 0 for gutter).convertImagesToBase64 function for converting regular images on the fly.htmlDocx.asBlob(content) to get a Blob/Buffer, then save it with saveAs(blob, 'test.docx').require('html-docx') or falls back to window.htmlDocx when no module loader is present.style tags that affect the DOCX output.The library leverages Microsoft Word's altchunks feature, which lets a DOCX file embed content in a different markup language. html-docx-js ships the HTML content inside an MHT document (which handles images), and when Word opens the file, it converts that embedded content to Word Processing ML and replaces the reference. This allows the conversion to happen without a dedicated converter.
Yes, html-docx-js is released under the MIT license, so it is free to use, modify, and distribute.
Yes, it works on Node.js (tested on v0.10.12) using Buffer instead of Blob. A Node.js usage sample is linked in the repository.
Only inlined base64 images sourced via DATA URI are supported. The demo includes a convertImagesToBase64 function to help convert regular images on the fly.
Because the conversion relies on Microsoft Word's altchunks feature, which is not supported by LibreOffice, Google Docs, or Word for Mac 2008. The resulting files are intended for Word 2007 and later.
Yes, for best results you should pass a complete, valid HTML document including DOCTYPE, html, and body tags. This allows CSS rules in style tags to be applied.
