{"id":31432201,"url":"https://github.com/turbodocx/html-to-docx","last_synced_at":"2025-09-30T10:32:18.134Z","repository":{"id":219616977,"uuid":"746796729","full_name":"TurboDocx/html-to-docx","owner":"TurboDocx","description":"HTML to DOCX converter","archived":false,"fork":false,"pushed_at":"2025-09-23T00:38:33.000Z","size":1579,"stargazers_count":112,"open_issues_count":24,"forks_count":24,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-23T01:15:38.609Z","etag":null,"topics":["document","documentation-generator","html-to-docx","javascript","nodejs","npm-module","npm-package"],"latest_commit_sha":null,"homepage":"https://TurboDocx.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"privateOmega/html-to-docx","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TurboDocx.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"custom":["https://www.TurboDocx.com"]}},"created_at":"2024-01-22T17:34:56.000Z","updated_at":"2025-09-22T23:34:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"23730cb9-4451-4cae-a2a8-e24d399f8ed8","html_url":"https://github.com/TurboDocx/html-to-docx","commit_stats":null,"previous_names":["turbodocx/html-to-docx"],"tags_count":45,"template":false,"template_full_name":null,"purl":"pkg:github/TurboDocx/html-to-docx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TurboDocx%2Fhtml-to-docx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TurboDocx%2Fhtml-to-docx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TurboDocx%2Fhtml-to-docx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TurboDocx%2Fhtml-to-docx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TurboDocx","download_url":"https://codeload.github.com/TurboDocx/html-to-docx/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TurboDocx%2Fhtml-to-docx/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":277200302,"owners_count":25778132,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-27T02:00:08.978Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["document","documentation-generator","html-to-docx","javascript","nodejs","npm-module","npm-package"],"created_at":"2025-09-30T10:30:42.170Z","updated_at":"2025-09-30T10:32:18.127Z","avatar_url":"https://github.com/TurboDocx.png","language":"JavaScript","funding_links":["https://www.TurboDocx.com"],"categories":[],"sub_categories":[],"readme":"[![TurboDocx](./banner.png)](https://www.turbodocx.com)\n\n@turbodocx/html-to-docx\n====================\n[![NPM Version][npm-image]][npm-url]\n[![GitHub Stars](https://img.shields.io/github/stars/turbodocx/html-to-docx?style=social)](https://github.com/turbodocx/html-to-docx)\n[![Type Script](https://shields.io/badge/TypeScript-3178C6?logo=TypeScript\u0026logoColor=FFF\u0026style=flat-square)](https://typescript.org)\n[![Discord](https://img.shields.io/badge/Discord-Join%20Us-7289DA?logo=discord)](https://discord.gg/NYKwz4BcpX)\n[![npm](https://img.shields.io/npm/dm/@turbodocx/html-to-docx)](https://www.npmjs.com/package/@turbodocx/html-to-docx)\n[![X](https://img.shields.io/badge/X-@TurboDocx-1DA1F2?logo=x\u0026logoColor=white)](https://twitter.com/TurboDocx)\n[![Embed TurboDocx in Your App in Minutes](https://img.shields.io/badge/Embed%20TurboDocx%20in%20Your%20App%20in%20Minutes-8A2BE2)](https://www.turbodocx.com/use-cases/embedded-api?utm_source=github\u0026utm_medium=repo\u0026utm_campaign=open_source)\n\nConvert 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.\n\nBased on the original work and assisted by the original contributors of [privateOmega/html-to-docx](https://github.com/privateOmega/html-to-docx), this library is now actively maintained and enhanced by TurboDocx, ensuring continuous improvements and long-term support for production environments.\n\n## Why @turbodocx/html-to-docx?\n\n🚀 **Lightning Fast Performance** - Pure JavaScript implementation with no dependencies on headless browsers or external binaries. Perfect for AI applications that need rapid document generation.\n\n🔄 **Active Maintenance \u0026 Support** - Backed by TurboDocx with regular updates, bug fixes, and feature enhancements. Not another abandoned open-source project.\n\n🤖 **AI-Ready Architecture** - Designed for modern AI workflows where speed matters. Generate thousands of documents without the overhead of browser automation.\n\n⚡ **Zero External Dependencies** - No need for Puppeteer, Chrome, or LibreOffice. Pure Node.js implementation that works in any environment.\n\n🎯 **Production Battle-Tested** - Used in production environments processing thousands of documents. Reliable, stable, and performant at scale.\n\n🛠️ **Developer Experience** - Full TypeScript support, comprehensive documentation, and extensive examples to get you up and running in minutes.\n\n## Installation\n\nUse the npm to install the project.\n\n```bash\nnpm install @turbodocx/html-to-docx\n```\n\n### TypeScript Support\n\nThis package includes TypeScript typings. No additional installation is required to use it with TypeScript projects.\n\n### TypeScript Example\n\n```typescript\nimport HtmlToDocx from \"@turbodocx/html-to-docx\";\n\nconst htmlString = `\u003c!DOCTYPE html\u003e\n    \u003chtml lang=\"en\"\u003e\n        \u003chead\u003e\n            \u003cmeta charset=\"UTF-8\" /\u003e\n            \u003ctitle\u003eDocument\u003c/title\u003e\n        \u003c/head\u003e\n        \u003cbody\u003e\n            \u003ch1\u003eHello world\u003c/h1\u003e\n        \u003c/body\u003e\n    \u003c/html\u003e`;\n\n// Basic usage\nasync function basicExample() {\n  const docx = await HtmlToDocx(htmlString);\n  // docx is ArrayBuffer in Node.js or Blob in browser environments\n}\n\n// With header\nasync function withHeader() {\n  const headerHtml = \"\u003cp\u003eDocument Header\u003c/p\u003e\";\n  const docx = await HtmlToDocx(htmlString, headerHtml);\n}\n\n// With document options\nasync function withOptions() {\n  const docx = await HtmlToDocx(htmlString, null, {\n    orientation: \"landscape\",\n    title: \"TypeScript Example\",\n    creator: \"TurboDocx\",\n    table: {\n      row: {\n        cantSplit: true,\n      },\n      borderOptions: {\n        size: 1,\n        color: \"000000\"\n      }\n    },\n    pageNumber: true,\n    footer: true\n  });\n}\n\n// With all parameters\nasync function complete() {\n  const headerHtml = \"\u003cp\u003eDocument Header\u003c/p\u003e\";\n  const footerHtml = \"\u003cp\u003ePage Footer\u003c/p\u003e\";\n  \n  const docx = await HtmlToDocx(\n    htmlString,\n    headerHtml,\n    {\n      orientation: \"landscape\",\n      pageSize: {\n        width: 12240,\n        height: 15840\n      },\n      margins: {\n        top: 1440,\n        right: 1800,\n        bottom: 1440,\n        left: 1800\n      },\n      title: \"Complete Example\",\n      creator: \"TurboDocx\",\n    },\n    footerHtml\n  );\n}\n```\n\nFor more comprehensive TypeScript examples, check out the following files in the `example/typescript` directory:\n\n- `typescript-example.ts` - A complete example showing how to generate and save DOCX files using TypeScript\n- `type-test.ts` - Demonstrates the type checking capabilities provided by the TypeScript definitions\n\n### Running the TypeScript Examples\n\nTo run the TypeScript examples:\n\n```bash\n# Navigate to the example directory\ncd example/typescript\n\n# Install ts-node globally (if not already installed)\nnpm install -g ts-node typescript\n\n# Ensure @turbodocx/html-to-docx is built and accessible\n# From the root directory of the project:\n# npm install\n# npm run build\n\n# Run the TypeScript example directly\nts-node typescript-example.ts\n```\n\nThis will generate two DOCX files in the `example/typescript` directory:\n- `basic-example.docx` - A simple document with minimal configuration\n- `advanced-example.docx` - A document with headers, footers, and advanced formatting options\n\n## Usage\n\n```js\nawait HTMLtoDOCX(htmlString, headerHTMLString, documentOptions, footerHTMLString)\n```\n\nfull fledged examples can be found under `example/`\n\n### Parameters\n\n- `htmlString` \u003c[String]\u003e clean html string equivalent of document content.\n- `headerHTMLString` \u003c[String]\u003e clean html string equivalent of header. Defaults to `\u003cp\u003e\u003c/p\u003e` if header flag is `true`.\n- `documentOptions` \u003c?[Object]\u003e\n  - `orientation` \u003c\"portrait\"|\"landscape\"\u003e defines the general orientation of the document. Defaults to portrait.\n  - `pageSize` \u003c?[Object]\u003e Defaults to U.S. letter portrait orientation.\n    - `width` \u003c[Number]\u003e width of the page for all pages in this section in [TWIP]. Defaults to 12240. Maximum 31680. Supports equivalent measurement in [pixel], [cm] or [inch].\n    - `height` \u003c[Number]\u003e height of the page for all pages in this section in [TWIP]. Defaults to 15840. Maximum 31680. Supports equivalent measurement in [pixel], [cm] or [inch].\n  - `margins` \u003c?[Object]\u003e\n    - `top` \u003c[Number]\u003e distance between the top of the text margins for the main document and the top of the page for all pages in this section in [TWIP]. Defaults to 1440. Supports equivalent measurement in [pixel], [cm] or [inch].\n    - `right` \u003c[Number]\u003e distance between the right edge of the page and the right edge of the text extents for this document in [TWIP]. Defaults to 1800. Supports equivalent measurement in [pixel], [cm] or [inch].\n    - `bottom` \u003c[Number]\u003e distance between the bottom of text margins for the document and the bottom of the page in [TWIP]. Defaults to 1440. Supports equivalent measurement in [pixel], [cm] or [inch].\n    - `left` \u003c[Number]\u003e distance between the left edge of the page and the left edge of the text extents for this document in [TWIP]. Defaults to 1800. Supports equivalent measurement in [pixel], [cm] or [inch].\n    - `header` \u003c[Number]\u003e distance from the top edge of the page to the top edge of the header in [TWIP]. Defaults to 720. Supports equivalent measurement in [pixel], [cm] or [inch].\n    - `footer` \u003c[Number]\u003e distance from the bottom edge of the page to the bottom edge of the footer in [TWIP]. Defaults to 720. Supports equivalent measurement in [pixel], [cm] or [inch].\n    - `gutter` \u003c[Number]\u003e amount of extra space added to the specified margin, above any existing margin values. This setting is typically used when a document is being created for binding in [TWIP]. Defaults to 0. Supports equivalent measurement in [pixel], [cm] or [inch].\n  - `title` \u003c?[String]\u003e title of the document.\n  - `subject` \u003c?[String]\u003e subject of the document.\n  - `creator` \u003c?[String]\u003e creator of the document. Defaults to `html-to-docx`\n  - `keywords` \u003c?[Array]\u003c[String]\u003e\u003e keywords associated with the document. Defaults to ['html-to-docx'].\n  - `description` \u003c?[String]\u003e description of the document.\n  - `lastModifiedBy` \u003c?[String]\u003e last modifier of the document. Defaults to `html-to-docx`.\n  - `revision` \u003c?[Number]\u003e revision of the document. Defaults to `1`.\n  - `createdAt` \u003c?[Date]\u003e time of creation of the document. Defaults to current time.\n  - `modifiedAt` \u003c?[Date]\u003e time of last modification of the document. Defaults to current time.\n  - `headerType` \u003c\"default\"|\"first\"|\"even\"\u003e type of header. Defaults to `default`.\n  - `header` \u003c?[Boolean]\u003e flag to enable header. Defaults to `false`.\n  - `footerType` \u003c\"default\"|\"first\"|\"even\"\u003e type of footer. Defaults to `default`.\n  - `footer` \u003c?[Boolean]\u003e flag to enable footer. Defaults to `false`.\n  - `font` \u003c?[String]\u003e font name to be used. Defaults to `Times New Roman`.\n  - `fontSize` \u003c?[Number]\u003e size of font in HIP(Half of point). Defaults to `22`. Supports equivalent measure in [pt].\n  - `complexScriptFontSize` \u003c?[Number]\u003e size of complex script font in HIP(Half of point). Defaults to `22`. Supports equivalent measure in [pt].\n  - `table` \u003c?[Object]\u003e\n    - `row` \u003c?[Object]\u003e\n      - `cantSplit` \u003c?[Boolean]\u003e flag to allow table row to split across pages. Defaults to `false`.\n    - `borderOptions` \u003c?[Object]\u003e\n      - `size` \u003c?[Number]\u003e denotes the border size. Defaults to `0`.\n      - `stroke` \u003c?[String]\u003e denotes the style of the borderStrike. Defaults to `nil`.\n      - `color` \u003c?[String]\u003e determines the border color. Defaults to `000000`.\n    - `addSpacingAfter` \u003c?[Boolean]\u003e flag to add an empty paragraph after tables for spacing. Defaults to `true`.\n  - `pageNumber` \u003c?[Boolean]\u003e flag to enable page number in footer. Defaults to `false`. Page number works only if footer flag is set as `true`.\n  - `skipFirstHeaderFooter` \u003c?[Boolean]\u003e flag to skip first page header and footer. Defaults to `false`.\n  - `lineNumber` \u003c?[Boolean]\u003e flag to enable line numbering. Defaults to `false`.\n  - `lineNumberOptions` \u003c?[Object]\u003e\n    - `start` \u003c[Number]\u003e start of the numbering - 1. Defaults to `0`.\n    - `countBy` \u003c[Number]\u003e skip numbering in how many lines in between + 1. Defaults to `1`.\n    - `restart` \u003c\"continuous\"|\"newPage\"|\"newSection\"\u003e numbering restart strategy. Defaults to `continuous`.\n  - `numbering` \u003c?[Object]\u003e\n    - `defaultOrderedListStyleType` \u003c?[String]\u003e default ordered list style type. Defaults to `decimal`.\n  - `decodeUnicode` \u003c?[Boolean]\u003e flag to enable unicode decoding of header, body and footer. Defaults to `false`.\n  - `lang` \u003c?[String]\u003e language localization code for spell checker to work properly. Defaults to `en-US`.\n  - `direction` \u003c?[String]\u003e text direction for RTL (right-to-left) languages. Set to `'rtl'` for Arabic, Hebrew, etc. Defaults to `'ltr'`.\n  - `preProcessing` \u003c?[Object]\u003e\n    - `skipHTMLMinify` \u003c?[Boolean]\u003e flag to skip minification of HTML. Defaults to `false`.\n- `footerHTMLString` \u003c[String]\u003e clean html string equivalent of footer. Defaults to `\u003cp\u003e\u003c/p\u003e` if footer flag is `true`.\n\n### Returns\n\n\u003c[Promise]\u003c[Buffer]|[Blob]\u003e\u003e\n\n## Notes\n\nCurrently page break can be implemented by having div with classname \"page-break\" or style \"page-break-after\" despite the values of the \"page-break-after\", and contents inside the div element will be ignored. `\u003cdiv class=\"page-break\" style=\"page-break-after: always;\"\u003e\u003c/div\u003e`\n\n\nCSS list-style-type for `\u003col\u003e` element are now supported. Just do something like this in the HTML:\n```\n  \u003col style=\"list-style-type:lower-alpha;\"\u003e\n    \u003cli\u003eList item\u003c/li\u003e\n    ...\n  \u003c/ol\u003e\n```\nList of supported list-style-types:\n- upper-alpha, will result in `A. List item`\n- lower-alpha, will result in `a. List item`\n- upper-roman, will result in `I. List item`\n- lower-roman, will result in `i. List item`\n- lower-alpha-bracket-end, will result in `a) List item`\n- decimal-bracket-end, will result in `1) List item`\n- decimal-bracket, will result in `(1) List item`\n- decimal, **(the default)** will result in `1. List item`\n\nAlso you could add attribute `data-start=\"n\"` to start the numbering from the n-th.\n\n`\u003col data-start=\"2\"\u003e` will start the numbering from ( B. b. II. ii. 2. )\n\n\n## RTL (Right-to-Left) Language Support\n\nThe library also supports RTL languages like Arabic and Hebrew. Use the `direction` option to enable RTL text flow:\n\n```javascript\nconst htmlString = `\n  \u003ch1\u003eمرحبا بالعالم\u003c/h1\u003e\n  \u003cp\u003eهذا نص تجريبي باللغة العربية ليظهر من اليمين إلى اليسار\u003c/p\u003e\n`;\n\nconst docx = await HTMLtoDOCX(htmlString, null, {\n  direction: 'rtl',        // Enable RTL text direction\n  lang: 'ar-SA',          // Arabic locale (or 'he-IL' for Hebrew)\n  font: 'Arial',          // Use a font that supports RTL characters\n});\n```\n\nFor more RTL examples, check `example/react-example/src/example-rtl.js`.\n\n## Font Compatibility\n\nFont family doesnt work consistently for all word processor softwares\n\n- Word Desktop work as intended\n- LibreOffice ignores the fontTable.xml file, and finds a font by itself\n- Word Online ignores the fontTable.xml file, and finds closest font in their font library\n\n## Contributing\n\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\nPlease make sure to branch new branches off of develop for contribution.\n\n## Support\n**Proudly Sponsored by TurboDocx** \n[![\"Proudly Sponsored by TurboDocx\"](https://image.typedream.com/cdn-cgi/image/width=1920,format=auto,fit=scale-down,quality=100/https://api.typedream.com/v0/document/public/de39171b-a5c9-49c5-bd9c-c2dfd5d632a2/2PZxyx12UwC5HrIA3p6lo16fCms_Group_16_1_.png)](https://www.TurboDocx.com)\n\n## License\n\nMIT\n\n[npm-image]: https://img.shields.io/npm/v/@turbodocx/html-to-docx.svg\n[npm-url]: https://npmjs.org/package/@turbodocx/html-to-docx\n[html-docx-js]: https://github.com/evidenceprime/html-docx-js \"html-docx-js\"\n[altchunks]: https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.altchunk?view=openxml-2.8.1 \"altchunks\"\n[libtidy]: https://github.com/jure/node-libtidy \"libtidy\"\n[String]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\"\n[Object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object \"Object\"\n[Number]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type \"Number\"\n[TWIP]: https://en.wikipedia.org/wiki/Twip \"TWIP\"\n[Array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array \"Array\"\n[Date]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date \"Date\"\n[Boolean]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type \"Boolean\"\n[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise \"Promise\"\n[Buffer]: https://nodejs.org/api/buffer.html#buffer_buffer \"Buffer\"\n[Blob]: https://developer.mozilla.org/en-US/docs/Web/API/Blob \"Blob\"\n[pixel]: https://en.wikipedia.org/wiki/Pixel#:~:text=Pixels%2C%20abbreviated%20as%20%22px%22,what%20screen%20resolution%20views%20it. \"pixel\"\n[cm]: https://en.wikipedia.org/wiki/Centimetre \"cm\"\n[inch]: https://en.wikipedia.org/wiki/Inch \"inch\"\n[pt]: https://en.wikipedia.org/wiki/Point_(typography) \"pt\"\n\n## Contributors\n\n\u003ca href=\"https://github.com/TurboDocx/html-to-docx/graphs/contributors\"\u003e\n  \u003cimg src=\"https://contrib.rocks/image?repo=turbodocx/html-to-docx\" /\u003e\n\u003c/a\u003e\n\nMade with [contrib.rocks](https://contrib.rocks).\n\n---\n\n**Note:** Currently optimized for Node.js environments. Browser support is planned for future releases.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fturbodocx%2Fhtml-to-docx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fturbodocx%2Fhtml-to-docx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fturbodocx%2Fhtml-to-docx/lists"}