🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

html-docx-ts

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
h

html-docx-ts

Convert HTML documents to docx format with header and footer.

0.0.5
latest
72

Supply Chain Security

100

Vulnerability

88

Quality

76

Maintenance

100

License

Version published
Weekly downloads
425
-8.21%
Maintainers
1
Weekly downloads
 
Created
Issues
2

html-docx-ts

NPM version

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

FAQs

Package last updated on 21 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts