html-docx-ts
v0.0.5
Published
Convert HTML documents to docx format with header and footer.
Downloads
1,053
Maintainers
Readme
html-docx-ts
Origin html-docx-js ,Rewrite html-docx-js-typescript .
Convert HTML documents to docx format with header and footer.
Installing
npm install html-docx-ts --save-dev
Usage
Support node.js and browser enviroment, including vue/react/angular.
Example:
If you want to display page numbers, you can make the string equal to 'pageNum'
import { asBlob } from 'html-docx-ts'
import { saveAs } from 'file-saver' //save the file
function exportDocx() {
//set the config
const HtmlStr = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<title>testTitle</title>
<body>
<div>
testContext
</div >
</body >
</html >`
const option = { orientation: 'portrait', margins: {} }
const headerConfig = {
leftStr: 'headerLeft',
centerStr: 'headerCenter',
rightStr: 'headerRight',
}
const footerConfig = {
leftStr: 'footerLeft',
centerStr: 'footerCenter',
rightStr: 'pageNum',//param equal to 'pageNum', that will show the page numbers
}
asBlob(HtmlStr, option, headerConfig, footerConfig).then(blobData => {
saveAs(blobData, `testDocument.docx`) // save as docx document
})
}
License
MIT