Installations
npm install html-docx-js
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
0.10.38
NPM Version
2.13.2
Score
92.4
Supply Chain
92.4
Quality
72.5
Maintenance
50
Vulnerability
98.9
License
Contributors
Unable to fetch Contributors
Languages
JavaScript (95.91%)
CoffeeScript (2.55%)
HTML (0.92%)
Smarty (0.62%)
Developer
Download Statistics
Total Downloads
2,849,208
Last Day
3,168
Last Week
13,620
Last Month
70,815
Last Year
850,774
GitHub Statistics
1,075 Stars
20 Commits
290 Forks
37 Watching
4 Branches
13 Contributors
Bundle Size
88.63 kB
Minified
27.43 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.3.1
Package Id
html-docx-js@0.3.1
Size
158.08 kB
NPM Version
2.13.2
Node Version
0.10.38
Publised On
17 May 2016
Total Downloads
Cumulative downloads
Total Downloads
2,849,208
Last day
-14.5%
3,168
Compared to previous day
Last week
-42.2%
13,620
Compared to previous week
Last month
11.1%
70,815
Compared to previous month
Last year
61.2%
850,774
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
html-docx-js
This is a very small library that is capable of converting HTML documents to DOCX format that is used by Microsoft Word 2007 and onward. It manages to perform the conversion in the browser by using a feature called 'altchunks'. In a nutshell, it allows embedding content in a different markup language. We are using MHT document to ship the embedded content to Word as it allows to handle images. After Word opens such file, it converts the external content to Word Processing ML (this is how the markup language of DOCX files is called) and replaces the reference.
Altchunks were not supported by Microsoft Word for Mac 2008 and are not supported by LibreOffice and Google Docs.
Compatibility
This library should work on any modern browser that supports Blobs
(either natively or via
Blob.js). It was tested on Google Chrome 36, Safari 7 and
Internet Explorer 10.
It also works on Node.js (tested on v0.10.12) using Buffer
instead of Blob
.
Images Support
This library supports only inlined base64 images (sourced via DATA URI). But it is easy to convert a
regular image (sourced from static folder) on the fly. If you need an example of such conversion you can checkout a demo page source (see function convertImagesToBase64
).
Usage and demo
Very minimal demo is available as test/sample.html
in the repository and
online. Please note that saving
files on Safari is a little bit convoluted and the only reliable method seems to be falling back
to a Flash-based approach (such as Downloadify).
Our demo does not include this workaround to keep things simple, so it will not work on Safari at
this point of time.
You can also find a sample for using it in Node.js environment here.
To generate DOCX, simply pass a HTML document (as string) to asBlob
method to receive Blob
(or Buffer
)
containing the output file.
var converted = htmlDocx.asBlob(content);
saveAs(converted, 'test.docx');
asBlob
can take additional options for controlling page setup for the document:
orientation
:landscape
orportrait
(default)margins
: map of margin sizes (expressed in twentieths of point, see WordprocessingML documentation for details):top
: number (default: 1440, i.e. 2.54 cm)right
: number (default: 1440)bottom
: number (default: 1440)left
: number (default: 1440)header
: number (default: 720)footer
: number (default: 720)gutter
: number (default: 0)
For example:
var converted = htmlDocx.asBlob(content, {orientation: 'landscape', margins: {top: 720}});
saveAs(converted, 'test.docx');
IMPORTANT: please pass a complete, valid HTML (including DOCTYPE, html
and body
tags).
This may be less convenient, but gives you possibility of including CSS rules in style
tags.
html-docx-js
is distributed as 'standalone' Browserify module (UMD). You can require
it as
html-docx
. If no module loader is available, it will register itself as window.htmlDocx
.
See test/sample.html
for details.
License
Copyright (c) 2015 Evidence Prime, Inc. See the LICENSE file for license rights and limitations (MIT).
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
branch protection is not maximal on development and all release branches
Details
- Info: 'allow deletion' disabled on branch 'master'
- Info: 'force pushes' disabled on branch 'master'
- Info: 'branch protection settings apply to administrators' is required to merge on branch 'master'
- Warn: 'stale review dismissal' is disabled on branch 'master'
- Warn: required approving review count is 1 on branch 'master'
- Warn: codeowners review is required - but no codeowners file found in repo
- Warn: 'last push approval' is disabled on branch 'master'
- Warn: no status checks found to merge onto branch 'master'
- Info: PRs are required in order to make changes on branch 'master'
Reason
Found 4/19 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 4 are checked with a SAST tool
Score
4
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to html-docx-js
html-docx-js-typescript
Convert HTML documents to docx format.
@types/html-docx-js
TypeScript definitions for html-docx-js
html-docx-js-extends
基于html-docx-js-typescript的扩展,支持将多段html转换为docx文档,并分段设置纵横方向,以及简单页眉和页码的设置.
html-docx-js-typescript-papersize-thenn
Convert HTML documents to docx format.