html-to-docx is a js library for converting HTML documents to DOCX format supported by Microsoft Word 2007+, LibreOffice Writer, Google Docs, WPS Writer etc.
It was inspired by html-docx-js project but mitigates the problem of documents generated being non-compatiable with word processors like Google Docs and libreOffice Writer that doesn't support altchunks feature.
Use the npm to install foobar.
npm install html-to-docx
await HTMLtoDOCX(htmlString, headerHTMLString, documentOptions)
full fledged examples can be found under example/
htmlString
<String> html string equivalent of document content.headerHTMLString
<String> html string equivalent of header.documentOptions
<?Object>orientation
<"portrait"|"landscape"> defines the general orientation of the document. Defaults to portrait.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 tohtml-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 tohtml-to-docx
.revision
<?Number> revision of the document. Defaults to1
.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 todefault
header
<?Boolean> flag to enable header. Defaults tofalse
.font
<?String> font name to be used. Defaults toTimes 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.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
MIT