Profile
Back to NewsBack
GitHub Trending 8 min
Reader Mode
TurboDocx/html-to-docx: HTML to DOCX converter

TurboDocx/html-to-docx: HTML to DOCX converter

15 hours ago

TurboDocx</a>

@turbodocx/html-to-docx ==================== [![NPM Version][npm-image]][npm-url] CodeQL</a> GitHub Stars</a> Type Script</a> Discord</a> npm</a> Agent Skills</a> Quickstart Skill</a> X</a> Embed TurboDocx in Your App in Minutes</a>

Convert HTML to Word, Google Docs, and DOCX files with the fastest, most reliable JavaScript library available. Built for modern applications that demand speed and precision—from AI-powered document generation to enterprise reporting systems.

Based on the original work and assisted by the original contributors of privateOmega/html-to-docx, this library is now actively maintained and enhanced by TurboDocx, ensuring continuous improvements and long-term support for production environments.

🌐 Explore the TurboDocx Ecosystem

| Package | Links | Description | |---------|-------|-------------| | API & SDK | Website</a> | Production-ready SDK for e-signature, document generation, template processing, and more | | TurboSign | Website</a> | Digital signature API for seamless e-signature workflows | | sdk | GitHub</a> | Official TurboDocx SDK for seamless API integration | | next-plugin-llms | GitHub</a> | Next.js plugin for automatic llms.txt generation | | n8n-nodes-turbodocx | npm</a> GitHub</a> | n8n community node for TurboDocx API & TurboSign | | TurboQuote | Website</a> | Sales quotes, proposals, and CPQ workflows with built-in e-signature |

Why @turbodocx/html-to-docx?

🚀 Lightning Fast Performance - Pure JavaScript implementation with no dependencies on headless browsers or external binaries. Perfect for AI applications that need rapid document generation.

🔄 Active Maintenance & Support - Backed by TurboDocx with regular updates, bug fixes, and feature enhancements. Not another abandoned open-source project.

🤖 AI-Ready Architecture - Designed for modern AI workflows where speed matters. Generate thousands of documents without the overhead of browser automation.

Zero External Dependencies - No need for Puppeteer, Chrome, or LibreOffice. Pure Node.js implementation that works in any environment.

🎯 Production Battle-Tested - Used in production environments processing thousands of documents. Reliable, stable, and performant at scale.

🛠️ Developer Experience - Full TypeScript support, comprehensive documentation, and extensive examples to get you up and running in minutes.

⚡ Skip the boilerplate — let an agent scaffold it for you

Have an AI coding agent (Claude Code, Cursor, Copilot, Codex, Gemini CLI, OpenCode) install @turbodocx/html-to-docx, generate a helper module, and write a working framework-appropriate route handler in one step:

npx skills add TurboDocx/quickstart

Then run /turbodocx-html-to-docx inside your agent. The skill will:

  1. Install @turbodocx/html-to-docx and any required peer dependencies
  2. Detect your project structure (Express, Next.js, Fastify, NestJS, plain Node.js, etc.)
  3. Generate a helper module and a framework-appropriate route/handler that returns a .docx response
  4. Add example usage matching your existing code patterns
Source:
github.com/TurboDocx/quickstart.

Installation

Use the npm to install the project.

npm install @turbodocx/html-to-docx

TypeScript Support

This package includes TypeScript typings. No additional installation is required to use it with TypeScript projects.

TypeScript Example

import HtmlToDocx from "@turbodocx/html-to-docx";

const htmlString = <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Document</title> </head> <body> <h1>Hello world</h1> </body> </html>;

// Basic usage async function basicExample() { const docx = await HtmlToDocx(htmlString); // docx is ArrayBuffer in Node.js or Blob in browser environments }

// With header async function withHeader() { const headerHtml = "<p>Document Header</p>"; const docx = await HtmlToDocx(htmlString, headerHtml); }

// With document options async function withOptions() { const docx = await HtmlToDocx(htmlString, null, { orientation: "landscape", title: "TypeScript Example", creator: "TurboDocx", table: { row: { cantSplit: true, }, borderOptions: { size: 1, color: "000000" } }, pageNumber: true, footer: true }); }

// With image processing options async function withImageOptions() { const htmlWithImages = <div> <img src="https://example.com/image.jpg" alt="Example"> </div>; const docx = await HtmlToDocx(htmlWithImages, null, { imageProcessing: { maxRetries: 3, // Retry failed image downloads up to 3 times verboseLogging: true, // Enable detailed logging for debugging downloadTimeout: 10000, // 10 second timeout per download attempt maxImageSize: 5242880 // 5MB max image size } }); }

// With all parameters async function complete() { const headerHtml = "<p>Document Header</p>"; const footerHtml = "<p>Page Footer</p>"; const docx = await HtmlToDocx( htmlString, headerHtml, { orientation: "landscape", pageSize: { width: 12240, height: 15840 }, margins: { top: 1440, right: 1800, bottom: 1440, left: 1800 }, title: "Complete Example", creator: "TurboDocx", }, footerHtml ); }

For more comprehensive TypeScript examples, check out the following files in the example/typescript directory:

  • typescript-example.ts - A complete example showing how to generate and save DOCX files using TypeScript
  • type-test.ts - Demonstrates the type checking capabilities provided by the TypeScript definitions

Running the TypeScript Examples

To run the TypeScript examples:

# Navigate to the example directory
cd example/typescript

Install ts-node globally (if not already installed)

npm install -g ts-node typescript

Ensure @turbodocx/html-to-docx is built and accessible

From the root directory of the project:

npm install

npm run build

Run the TypeScript example directly

ts-node typescript-example.ts

This will generate two DOCX files in the example/typescript directory:

  • basic-example.docx - A simple document with minimal configuration
  • advanced-example.docx - A document with headers, footers, and advanced formatting options

Browser Standalone Build

The library provides a standalone browser build that bundles all dependencies into a single file. This allows you to use the library directly in HTML pages without any build tools or module bundlers.

Build Outputs

When you run npm run build, four distribution files are generated:

| File | Format | Size | Dependencies | Use Case | |------|--------|------|--------------|----------| | dist/html-to-docx.esm.js | ES Module | ~1.6 MB | External | Node.js ESM, server-side bundling | | dist/html-to-docx.umd.js | UMD | ~1.6 MB | External | Node.js require, AMD | | dist/html-to-docx.browser.esm.js | ES Module | ~1.6 MB | All bundled | Browser bundlers (Next.js, Vite, webpack) | | dist/html-to-docx.browser.js | IIFE | ~1.6 MB | All bundled | Direct browser usage via Chat with me