First module for docxtemplater.
You will need docxtemplater v1: npm install docxtemplater
install this module: npm install docxtemplater-image-module
Your docx should contain the text: {%myImage}
ImageModule = require 'docxtemplater-image-module'
imageModule = new ImageModule({ centered: false })
docx = new DocxGen()
.attachModule(imageModule)
.load(content)
.setData({ myImage: { path: 'examples/image.png', size: [650, 200] })
.render()
buffer = docx
.getZip()
.generate( {type: 'nodebuffer' })
fs.writeFile("test.docx",buffer);
You can center the images using new ImageModule({centered:true}) instead
For the imagereplacer to work, the image tag: {%image}
need to be in its own <w:p>
, so that means that you have to put a new line after and before the tag.
You can build the coffee into js by running gulp
(this will watch the directory for changes)
You can test that everything works fine using the command mocha
. This will also create 3 docx files under the root directory that you can open to check if the docx are correct