Skip to content

daz/docxtemplater-image-module

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

First module for docxtemplater.

Build Status Download count Current tag Issues closed

Installation:

You will need docxtemplater v1: npm install docxtemplater

install this module: npm install docxtemplater-image-module

Usage

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);

Options

You can center the images using new ImageModule({centered:true}) instead

Notice

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.

Building

You can build the coffee into js by running gulp (this will watch the directory for changes)

Testing

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

About

A module to insert images with docxtemplater

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • CoffeeScript 97.1%
  • JavaScript 2.9%