Commit ed8ce5d4 by MaxRcd

Updated package.json / readme

Added latest build
parent 8ad57248
...@@ -4,5 +4,4 @@ test/ ...@@ -4,5 +4,4 @@ test/
js/ Install from NPM js/ Install from NPM
node_modules node_modules
coverage/ coverage/
build
.idea/ .idea/
**Readme cleaned. To be updated.** Open source docxtemplater image module
==========================================
This repository holds a updated version of docxtemplater image module.
This package is open source. There is also a [paid version](https://docxtemplater.com/modules/image/) maintained by docxtemplater author.
Note this version is compatible with docxtemplater 3.x.
Installation
=============
You first need to install docxtemplater by following its [installation guide](https://docxtemplater.readthedocs.io/en/latest/installation.html#node).
For Node.js install this package
```
npm install open-docxtemplater-image-module
```
For the browser find builds in `build/` directory.
Usage
=====
To render an image, your **docx** or **pptx** template should contain the text: `{%image}`
```javascript
//Node.js example
var ImageModule = require('open-docxtemplater-image-module');
//Below the options that will be passed to ImageModule instance
var opts = {}
opts.centered = false; //Set to true to always center images
opts.fileType = "docx"; //Or pptx
//Pass your image loader
opts.getImage = function(tagValue, tagName) {
//tagValue is 'examples/image.png'
//tagName is 'image'
return fs.readFileSync(tagValue);
}
//Pass the function that return image size
opts.getSize = function(img, tagValue, tagName) {
//img is the image returned by opts.getImage()
//tagValue is 'examples/image.png'
//tagName is 'image'
//tip: you can use node module 'image-size' here
return [150, 150];
}
var imageModule = new ImageModule(opts);
var zip = new JSZip(content);
var doc = new Docxtemplater()
.attachModule(imageModule)
.loadZip(zip)
.setData({image: 'examples/image.png'})
.render();
var buffer = doc
.getZip()
.generate({type:"nodebuffer"});
fs.writeFile("test.docx",buffer);
```
Some notes regarding the template:
* **docx** files: the placeholder `{%image}` must be in a dedicated paragraph.
* **pptx** files: the placeholder `{%image}` must be in a dedicated text cell.
Centering images
================
You can center all images using either passing the option `opts.centered = true` or one by one using `{%%image}` instead of `{%image}` in your templates.
In **pptx** generated documents, images are centered vertically and horizontally relative to the parent cell.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
{ {
"name": "open-docxtemplater-image-module", "name": "open-docxtemplater-image-module",
"version": "1.0.2", "version": "1.0.3",
"description": "Open Source Image Module for docxtemplater", "description": "Open Source Image Module for docxtemplater",
"main": "js/index.js", "main": "js/index.js",
"scripts": { "scripts": {
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
"test:es6": "mocha es6/test.js", "test:es6": "mocha es6/test.js",
"lint": "eslint .", "lint": "eslint .",
"test": "npm run compile && npm run test:compiled", "test": "npm run compile && npm run test:compiled",
"browserify": "mkdir build -p && browserify --insert-global-vars __filename,__dirname -r ./js/index.js -s ImageModule > build/imagemodule.js", "browserify": "rimraf build && mkdirp build && browserify --insert-global-vars __filename,__dirname -r ./js/index.js -s ImageModule > build/imagemodule.js",
"uglify": "uglifyjs build/imagemodule.js > build/imagemodule.min.js" "uglify": "uglifyjs build/imagemodule.js > build/imagemodule.min.js"
}, },
"devDependencies": { "devDependencies": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment