puredocx-image-templater-free
v1.0.2
Published
This free module allows to add an image using the {%image} tag. If you want to replace an existing image please purchase the paid version : https://puredocx.com
Downloads
7
Readme
Installation
With modules:
npm install --save @mllx87/puredocx
Usage
First, download the input.docx file and place it in the same folder as your JavaScript file.
const Puredocx = require("@mllx87/puredocx");
var puredocx = new Puredocx()
var substitutions = {
"title":"hello",
"summary":"New World",
"staff":30,
"company":"mllx"
};
puredocx.render("input.docx",substitutions,"output.docx")
Images,Assuming your docx or pptx template contains only the text {%image}
const Puredocx = require("@mllx87/puredocx");
var puredocx = new Puredocx()
var substitutions = {
"title":"hello",
"summary":"New World",
"staff":30,
"company":"mllx",
"image": "99e36.jpeg"
};
puredocx.render("input.docx",substitutions,"output.docx")
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.imageOptions.centered = true
.
If you would like to choose which images should be centered one by one:
- Set the global switch to false
opts.imageOptions.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.
Supported image format in given data :
- Base64 string
- Absolute path file
- relative path file (absolute is prior to relative in test)
- URL : https://www.puredocx.com/static/img/company.png
You can pass imageRootPath option for setting the root folder for your images.
var puredocx = new Puredocx({
"imageOptions": {
imageRootPath: "/path/to/your/image/dir"
}
})
For more options see:PureDocx