.docx generator working with templates and data (like Mustache)

docxtemplater v1

docxtemplater is a library to generate docx/pptx documents from a docx/pptx template. It can replace {placeholders} with data and also supports loops and conditions. The templates can be edited by non-programmers, eg for example your clients.

Note: The CLI will soon be moved to another repository : keep posted on

Demo Site

Installation: npm install docxtemplater

var fs = require('fs');
var Docxtemplater = require('docxtemplater');
//Load the docx file as a binary 
var content = fs
    .readFileSync(__dirname + "/input.docx", "binary");
var doc = new Docxtemplater(content);
//set the templateVariables 
    "description":"New Website"
//apply them (replace all occurences of {first_name} by Hipp, ...) 
var buf = doc.getZip()

You can download input.docx and put it in the same folder than your script.

You can directly download built versions from github :

Thanks to pykiss, it's now possible to install docxtemplater with bower: This in an unofficial method to install docxtemplater in the browser

bower install --save docxtemplater-pykiss
git clone && cd docxtemplater
# git checkout v1.0.4 # Optional
npm install -g gulp jasmine-node uglify-js browserify
npm install
gulp allCoffee
mkdir build -p
browserify -r ./js/docxgen.js -s Docxgen > build/docxgen.js
uglifyjs build/docxgen.js > build/docxgen.min.js # Optional

The -s Docxgen will export docxgen to window.Docxgen for easy usage (on some systems, it might export it in window.docxgen (see

Create the following html

    <script src="build/docxgen.js"></script> 
    <script src="vendor/FileSaver.min.js"></script> 
    <script src="vendor/jszip-utils.js"></script> 
    Mandatory in IE 6, 7, 8 and 9.
    <!--[if IE]>
        <script type="text/javascript" src="examples/vendor/jszip-utils-ie.js"></script>
    var loadFile=function(url,callback){
        if (err) { throw e};
        doc=new Docxgen(content);
        doc.setData( {"first_name":"Hipp",
            "description":"New Website"
        ) //set the templateVariables
        doc.render() //apply them (replace all occurences of {first_name} by Hipp, ...)
        out=doc.getZip().generate({type:"blob"}) //Output the document using Data-URI

The full documentation of v1 can be found on read the docs.

See for information about how to migrate from 0.7

They are a few similar libraries that work with docx, here’s a list of those I know a bit about:

  • docx4j :JAVA, this is probably the biggest docx library out there. They is no built in templating engine, but you can generate your docx yourself programmatically
  • docx.js: Javascript in the browser, you can create (not modify) your docx from scratch, but only do very simple things such as adding non formatted text
  • xlsx-templater : its working quite well, does the same as here but for xlsx


Functionality can be added with modules. They is yet no doc for the modules because it is not completely mature yet, but you can open an issue if you have any question about it.

Here is the list of existing modules:

  • Chart Module using the syntax: {$chart} , user contributed
  • Image module using the syntax: {%image},

Professional Support

I can give your company support for installing, extending, answering support questions, or maintainning your app that runs docxtemplater. You can find my email address on my profile