Gathering detailed insights and metrics for @turbodocx/html-to-docx
Gathering detailed insights and metrics for @turbodocx/html-to-docx
Gathering detailed insights and metrics for @turbodocx/html-to-docx
Gathering detailed insights and metrics for @turbodocx/html-to-docx
npm install @turbodocx/html-to-docx
Typescript
Module System
Node Version
NPM Version
v1.13.4
Updated on Jun 05, 2025
v1.13.3 - Typescript Typings, Dep Updates , and Security MD
Updated on May 31, 2025
v1.13.1 - Typescript Typings, Dep Updates , and Security MD
Updated on May 31, 2025
v1.13.0 - Typescript Typings and Dep Updates
Updated on May 31, 2025
v1.12.0 - Add ability to skip spacing after table option
Updated on Mar 22, 2025
v1.11.0 - Add support for <a> inside of <span>
Updated on Feb 27, 2025
JavaScript (98.23%)
TypeScript (1.2%)
HTML (0.35%)
CSS (0.19%)
Shell (0.03%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
89 Stars
523 Commits
16 Forks
2 Watchers
43 Branches
20 Contributors
Updated on Jul 10, 2025
Latest Version
1.13.4
Package Id
@turbodocx/html-to-docx@1.13.4
Unpacked Size
3.48 MB
Size
826.46 kB
File Count
6
NPM Version
10.8.2
Node Version
18.20.8
Published on
Jun 05, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
12
22
@turbodocx/html-to-docx
is a powerful JavaScript library designed to convert HTML documents to DOCX format, compatible with Microsoft Word 2007+, LibreOffice Writer, Google Docs, WPS Writer, and other word processors. Inspired by @PrivateOmega, this is supported by TurboDocx to ensure ongoing development and improvements.
While @turbodocx/html-to-docx
is robust and used in production environments, it is continually evolving. Please ensure it meets your specific needs through thorough testing. Note that it currently does not work directly in the browser.
Use the npm to install the project.
1npm install @turbodocx/html-to-docx
This package includes TypeScript typings. No additional installation is required to use it with TypeScript projects.
1import HtmlToDocx from "@turbodocx/html-to-docx"; 2 3const htmlString = `<!DOCTYPE html> 4 <html lang="en"> 5 <head> 6 <meta charset="UTF-8" /> 7 <title>Document</title> 8 </head> 9 <body> 10 <h1>Hello world</h1> 11 </body> 12 </html>`; 13 14// Basic usage 15async function basicExample() { 16 const docx = await HtmlToDocx(htmlString); 17 // docx is ArrayBuffer in Node.js or Blob in browser environments 18} 19 20// With header 21async function withHeader() { 22 const headerHtml = "<p>Document Header</p>"; 23 const docx = await HtmlToDocx(htmlString, headerHtml); 24} 25 26// With document options 27async function withOptions() { 28 const docx = await HtmlToDocx(htmlString, null, { 29 orientation: "landscape", 30 title: "TypeScript Example", 31 creator: "TurboDocx", 32 table: { 33 row: { 34 cantSplit: true, 35 }, 36 borderOptions: { 37 size: 1, 38 color: "000000" 39 } 40 }, 41 pageNumber: true, 42 footer: true 43 }); 44} 45 46// With all parameters 47async function complete() { 48 const headerHtml = "<p>Document Header</p>"; 49 const footerHtml = "<p>Page Footer</p>"; 50 51 const docx = await HtmlToDocx( 52 htmlString, 53 headerHtml, 54 { 55 orientation: "landscape", 56 pageSize: { 57 width: 12240, 58 height: 15840 59 }, 60 margins: { 61 top: 1440, 62 right: 1800, 63 bottom: 1440, 64 left: 1800 65 }, 66 title: "Complete Example", 67 creator: "TurboDocx", 68 }, 69 footerHtml 70 ); 71}
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 TypeScripttype-test.ts
- Demonstrates the type checking capabilities provided by the TypeScript definitionsTo run the TypeScript examples:
1# Navigate to the example directory 2cd example/typescript 3 4# Install ts-node globally (if not already installed) 5npm install -g ts-node typescript 6 7# Ensure @turbodocx/html-to-docx is built and accessible 8# From the root directory of the project: 9# npm install 10# npm run build 11 12# Run the TypeScript example directly 13ts-node typescript-example.ts
This will generate two DOCX files in the example/typescript
directory:
basic-example.docx
- A simple document with minimal configurationadvanced-example.docx
- A document with headers, footers, and advanced formatting options1await HTMLtoDOCX(htmlString, headerHTMLString, documentOptions, footerHTMLString)
full fledged examples can be found under example/
htmlString
<String> clean html string equivalent of document content.headerHTMLString
<String> clean html string equivalent of header. Defaults to <p></p>
if header flag is true
.documentOptions
<?Object>
orientation
<"portrait"|"landscape"> defines the general orientation of the document. Defaults to portrait.pageSize
<?Object> Defaults to U.S. letter portrait orientation.
width
<Number> 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.height
<Number> 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.margins
<?Object>
top
<Number> 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.right
<Number> 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.bottom
<Number> 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.left
<Number> 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.header
<Number> 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.footer
<Number> 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.gutter
<Number> 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.title
<?String> title of the document.subject
<?String> subject of the document.creator
<?String> creator of the document. Defaults to html-to-docx
keywords
<?Array<String>> keywords associated with the document. Defaults to ['html-to-docx'].description
<?String> description of the document.lastModifiedBy
<?String> last modifier of the document. Defaults to html-to-docx
.revision
<?Number> revision of the document. Defaults to 1
.createdAt
<?Date> time of creation of the document. Defaults to current time.modifiedAt
<?Date> time of last modification of the document. Defaults to current time.headerType
<"default"|"first"|"even"> type of header. Defaults to default
.header
<?Boolean> flag to enable header. Defaults to false
.footerType
<"default"|"first"|"even"> type of footer. Defaults to default
.footer
<?Boolean> flag to enable footer. Defaults to false
.font
<?String> font name to be used. Defaults to Times New Roman
.fontSize
<?Number> size of font in HIP(Half of point). Defaults to 22
. Supports equivalent measure in pt.complexScriptFontSize
<?Number> size of complex script font in HIP(Half of point). Defaults to 22
. Supports equivalent measure in pt.table
<?Object>
pageNumber
<?Boolean> flag to enable page number in footer. Defaults to false
. Page number works only if footer flag is set as true
.skipFirstHeaderFooter
<?Boolean> flag to skip first page header and footer. Defaults to false
.lineNumber
<?Boolean> flag to enable line numbering. Defaults to false
.lineNumberOptions
<?Object>
numbering
<?Object>
defaultOrderedListStyleType
<?String> default ordered list style type. Defaults to decimal
.decodeUnicode
<?Boolean> flag to enable unicode decoding of header, body and footer. Defaults to false
.lang
<?String> language localization code for spell checker to work properly. Defaults to en-US
.preProcessing
<?Object>
skipHTMLMinify
<?Boolean> flag to skip minification of HTML. Defaults to false
.footerHTMLString
<String> clean html string equivalent of footer. Defaults to <p></p>
if footer flag is true
.Currently 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. <div class="page-break" style="page-break-after: always;"></div>
CSS list-style-type for <ol>
element are now supported. Just do something like this in the HTML:
<ol style="list-style-type:lower-alpha;">
<li>List item</li>
...
</ol>
List of supported list-style-types:
A. List item
a. List item
I. List item
i. List item
a) List item
1) List item
(1) List item
1. List item
Also you could add attribute data-start="n"
to start the numbering from the n-th.
<ol data-start="2">
will start the numbering from ( B. b. II. ii. 2. )
Font family doesnt work consistently for all word processor softwares
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to branch new branches off of develop for contribution.
Proudly Sponsored by TurboDocx
MIT
Made with contrib.rocks.
No vulnerabilities found.
No security vulnerabilities found.