Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
docxtemplater-image-module
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
npm
docxtemplater-image-module
Commits
d4bf8692
Commit
d4bf8692
authored
Sep 24, 2015
by
Edgar HIPP
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update readme for v1
parent
d2e60b25
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
9 deletions
+30
-9
readme.md
+30
-9
No files found.
readme.md
View file @
d4bf8692
First module for docxtemplater.
The v1 has added two mandatory arguments:
`opts.getImage`
and
`opts.getSize`
. See Usage (v1)
[
![Build Status
](
https://travis-ci.org/open-xml-templating/docxtemplater-image-module.svg?branch=master&style=flat
)
](https://travis-ci.org/open-xml-templating/docxtemplater-image-module)
[
![Build Status
](
https://travis-ci.org/open-xml-templating/docxtemplater-image-module.svg?branch=master&style=flat
)
](https://travis-ci.org/open-xml-templating/docxtemplater-image-module)
[
![Download count
](
http://img.shields.io/npm/dm/docxtemplater-image-module.svg?style=flat
)
](https://www.npmjs.org/package/docxtemplater-image-module)
[
![Download count
](
http://img.shields.io/npm/dm/docxtemplater-image-module.svg?style=flat
)
](https://www.npmjs.org/package/docxtemplater-image-module)
...
@@ -11,13 +11,21 @@ You will need docxtemplater v1: `npm install docxtemplater`
...
@@ -11,13 +11,21 @@ You will need docxtemplater v1: `npm install docxtemplater`
install this module:
`npm install docxtemplater-image-module`
install this module:
`npm install docxtemplater-image-module`
# Usage
# Usage
(v1)
Your docx should contain the text:
`{%image}`
Your docx should contain the text:
`{%image}`
ImageModule=require(‘docxtemplater-image-module’)
ImageModule=require(‘docxtemplater-image-module’)
imageModule=new ImageModule({centered:false})
imageModule=new ImageModule({centered:false})
opts = {}
opts.getImage=function(tagValue) {
return fs.readFileSync(tagValue,'binary');
}
opts.getSize=function(img,tagValue) {
return [150,150];
}
docx=new DocxGen()
docx=new DocxGen()
.attachModule(imageModule)
.attachModule(imageModule)
...
@@ -31,25 +39,38 @@ Your docx should contain the text: `{%image}`
...
@@ -31,25 +39,38 @@ Your docx should contain the text: `{%image}`
fs.writeFile("test.docx",buffer);
fs.writeFile("test.docx",buffer);
# Options
You can center the images using new ImageModule({centered:true}) instead
To understand what
`img`
and
`tagValue`
mean, lets take an example :
## Size
If your template is :
{%myImage}
and your data:
{
"myImage":'sampleImage.png'
}
tagValue will be equal to "sampleImage.png" , and img will be what ever the getImage function returned
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.
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’
](
https://www.npmjs.com/package/image-size
)
For this, you will need to install the
[
npm package ‘image-size’
](
https://www.npmjs.com/package/image-size
)
then, write:
then, write:
imageModule=new ImageModule({centered:false})
opts = {centered:false}
imageModule.getSizeFromData=function(imgData
) {
opts.getImage=function(img
) {
sizeOf=require('image-size');
sizeOf=require('image-size');
sizeObj=sizeOf(img
Data
);
sizeObj=sizeOf(img);
console.log(sizeObj);
console.log(sizeObj);
return [sizeObj.width,sizeObj.height];
return [sizeObj.width,sizeObj.height];
}
}
imageModule=new ImageModule(opts)
# Centering images
You can center the images using new ImageModule({centered:true}) instead
# Notice
# Notice
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment