GithubHelp home page GithubHelp logo

ssured / docxtemplater-image-module Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bahulneel/docxtemplater-image-module

0.0 1.0 0.0 242 KB

A module to insert images with docxtemplater

CoffeeScript 97.26% JavaScript 2.74%

docxtemplater-image-module's Introduction

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: {%image}

ImageModule=require(‘docxtemplater-image-module’)

imageModule=new ImageModule({centered:false})

docx=new DocxGen()
    .attachModule(imageModule)
    .load(content)
    .setData({image:'examples/image.png'})
    .render()

buffer= docx
        .getZip()
        .generate({type:"nodebuffer"})

fs.writeFile("test.docx",buffer);

Options

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

Size

You can set the size of the image to what ever you want in pixel. By default it will be 150x150. One of the most useful cases of this is to set the images to be the size of that image.

For this, you will need to install the npm package ‘image-size’ then, write:

imageModule=new ImageModule({centered:false})
imageModule.getSizeFromData=function(imgData) {
   sizeOf=require('image-size');
   sizeObj=sizeOf(imgData);
   console.log(sizeObj);
   return [sizeObj.width,sizeObj.height];
}

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

docxtemplater-image-module's People

Contributors

edi9999 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.