You are currently offline, serving cached version

What is docxtemplater ?

docxtemplater is a mail merging tool that is used programmatically and handles conditions, loops, and can be extended to insert images, html, or tables.

docxtemplater uses Javascript objects (or JSON) as data input, so it can also be used easily from other languages (see docker version). It handles docx, pptx and with a plugin xlsx templates.

It works in the same way as a templating engine, you give it a template + some data and it will output a generated document.

Many solutions like docx.js, docx4j, python-docx can generate docx, but they require you to write specific code to create a title, an image, …

In contrast, docxtemplater is based on the concepts of tags, and each type of tag exposes a feature to the user writing the template.

Why I advise against writing a similar library from scratch

Docx is a zipped format that contains some xml. If you want to build a simple templating system to replace all {tags} by their values, it will be challenging, because the {tag} is sometimes internally separated into:


The fact that the tags can be splitted into multiple xml tags makes the code challenging to write. I had to rewrite most of the parsing engine between version 2 and version 3 of docxtemplater to make the code more straighforward: See the migration here

If you want to have loops to iterate over an array, it will become even more complicated.

docxtemplater provides a very simple API that gives you abstraction to deal with loops, conditions, and other features.

If you need additional features, you can either build your own module, or use one of the paid modules that you can find on the docxtemplater website

Talk with sales Contact us