open-docxtemplater-image-module
Advanced tools
Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "open-docxtemplater-image-module", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Open Source Image Module for docxtemplater", | ||
@@ -14,3 +14,3 @@ "main": "js/index.js", | ||
"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" | ||
@@ -17,0 +17,0 @@ }, |
@@ -1,1 +0,84 @@ | ||
**Readme cleaned. To be updated.** | ||
Open source docxtemplater image module | ||
========================================== | ||
This repository holds an 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). | ||
For Node.js install this package: | ||
``` | ||
npm install open-docxtemplater-image-module | ||
``` | ||
For the browser find builds in `build/` directory. | ||
Alternatively, you can create your own build from the sources: | ||
``` | ||
npm run compile | ||
npm run browserify | ||
npm run uglify | ||
``` | ||
Usage | ||
===== | ||
Assuming your **docx** or **pptx** template contains only 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 templates: | ||
* **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 by setting the global switch to true `opts.centered = true`. | ||
If you would like to choose which images should be centered one by one: | ||
* Set the global switch to false `opts.centered = false`. | ||
* Use `{%image}` for images that shouldn't be centered. | ||
* Use `{%%image}` for images that you would like to see centered. | ||
In **pptx** generated documents, images are centered vertically and horizontally relative to the parent cell. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
355473
17
5773
85
2
7
1