DOCX templates have multiple value formatters. One of them is the picture formatter. You can use it to dynamically insert pictures into DOCX documents.
Let us look at a few examples.
Insert a placeholder picture into your DOCX template. This placeholder will be replaced with a real picture in the final document.
Next, place the picture tag in the AltText section of the placeholder picture.
{{imageData}:picture}
The formatter accepts URLs. The URL must be publicly anonymously available (no authentication).
For the template from the picture above to work you need to use JSON object like this:
{
"imageData": "https://plumsail.com/docs/documents/v1.x/_images/plumsail-logo.png"
}
Also, the formatter supports Base64 strings as pictures. Thus, for the template from the picture above to work you will need to pass something like this:
{
"imageData": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIoAAAAyCAYAAACDHkN8AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAB3RJTUUH5AYDDA8z7aYtxwAACOdJREFUeJztnG9sE/cZx79JuByJTVKKXajjkhSnEknAFgxthKglVdaQjgotlaq9AaSplVZ4NQl4OQ3EqxVV24uJPxLbC4I0oTCYMpgWV5Q0IwTU/JkNdgjxQZy4dpwzJJc4di7nP3vh2LNjOzn77pcSdB/JSnz3u9/z2P7e83ue584uiEajUSgorEDhj+2AwtpAEYqCKNaRNtDzVxvGBiZRsVMDQ4MOFTs2kTapQADiQhHmw5gYnsLE8BT6r4+gtrkS9UdrULa5lLRpBRkhvvQI86GU53azE+0nuvG0+wfSphVkZBWEEk7bNuMN4PbZh4pY1hDEhRLiQ1n33T77EI4eN2kXFGTgR4koydy7/BizkwHSbihIhLhQgtP8svunXH7cu2wj7YaCRIgLZdozt+KYJ3fH8ej2c9KuKEiAqFACUzyEYPYcJRlFKK82RIUy7fGLHusdmVbE8gpDVCice+VlJxlFKK8uZIUiIj9JxjsyDY/9JSFvFKRAVCgTT6ZyPsYzpAjlVYSsUIZz/9A99hcEPInhsrDoOP0ALgtLzMZawGZ24i9H/p3TMcQuCnKeOQS5hZyPExtReL8A9hmXtp1WUdAayjMeM27xgelxY3erIWe/1iosw4FWUykXYe2dTsxM5NbkJCaUieHclx0AmGWDWAiEUFy6vGssM432k//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HHNQgj1xCZkre5U9JyHUUVH8o6p4K85F71RCMQHNcQGrmGsCf7XfBioXYcB/2zs5LnUSBL3n0UAAi7vkXY24vwROyRK1TtF6Dr/5CveYVVRJJQkokucAh7ehD29CDC9iEyO4ZoMPMtkYUbt4Oq/QLU9l/LYVphFZBNKAqvN8ovVyuIQhGKgigUoSiIQhGKgigUoSiIQhGKgij+B4V7vYMAPildAAAAAElFTkSuQmCC"
}
Please click on the links below to find instructions on how to insert an image file into your template using various services.
You can also insert a picture just adding a text token into the DOCX template.
{{imageData}:picture}
Then use either a public URL
{
"imageData": "https://plumsail.com/docs/documents/v1.x/_images/plumsail-logo.png"
}
or a base64 code to replace the token with a picture.
{
"imageData": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIoAAAAyCAYAAACDHkN8AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAB3RJTUUH5AYDDA8z7aYtxwAACOdJREFUeJztnG9sE/cZx79JuByJTVKKXajjkhSnEknAFgxthKglVdaQjgotlaq9AaSplVZ4NQl4OQ3EqxVV24uJPxLbC4I0oTCYMpgWV5Q0IwTU/JkNdgjxQZy4dpwzJJc4di7nP3vh2LNjOzn77pcSdB/JSnz3u9/z2P7e83ue584uiEajUSgorEDhj+2AwtpAEYqCKNaRNtDzVxvGBiZRsVMDQ4MOFTs2kTapQADiQhHmw5gYnsLE8BT6r4+gtrkS9UdrULa5lLRpBRkhvvQI86GU53azE+0nuvG0+wfSphVkZBWEEk7bNuMN4PbZh4pY1hDEhRLiQ1n33T77EI4eN2kXFGTgR4koydy7/BizkwHSbihIhLhQgtP8svunXH7cu2wj7YaCRIgLZdozt+KYJ3fH8ej2c9KuKEiAqFACUzyEYPYcJRlFKK82RIUy7fGLHusdmVbE8gpDVCice+VlJxlFKK8uZIUiIj9JxjsyDY/9JSFvFKRAVCgTT6ZyPsYzpAjlVYSsUIZz/9A99hcEPInhsrDoOP0ALgtLzMZawGZ24i9H/p3TMcQuCnKeOQS5hZyPExtReL8A9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jSWLY8LNTsR4RwxwRAUCQCs29ZKdH4FaYjKUYSRv2Fh4CtEJeYg2SjaUo+Sg7eIzK0gD6KT2WhwEiHHNQgj1xCZkre5U9JyHUUVH8o6p4K85F71RCMQHNcQGrmGsCf7XfBioXYcB/2zs5LnUSBL3n0UAAi7vkXY24vwROyRK1TtF6Dr/5CveYVVRJJQkokucAh7ehD29CDC9iEyO4ZoMPMtkYUbt4Oq/QLU9l/LYVphFZBNKAqvN8ovVyuIQhGKgigUoSiIQhGKgigUoSiIQhGKgij+B4V7vYMAPildAAAAAElFTkSuQmCC"
}
Please click on the links below to find instructions on how to insert an image file into your template using various services.
The picture formatter can be used with some additional options. Let’s check them all.
Note
You can easily combine different options within one token in order to achieve the desired result.
For example, {{imageData}:picture(Auto, 300, Fit):rotate(90):flip(X)}
Use resizing options with the formatter, for example, {{imageData}:picture(300,200)}
.
Also you can specify only the width or height parameter and add Auto to automatically calculate another dimension.
For example, {{imageData}:picture(300, Auto)}
.
This option rotates the source picture by 90, 180, or 270 degrees.
To use the option, add it to the picture formatter in your template.
{{imageData}:picture(100):rotate(90)}
This option flips the image horizontally and/or vertically.
Add it to the picture formatter in your template.
{{imageData}:picture(100):flip(X)}
{{imageData}:picture(100):flip(Y)}
{{imageData}:picture(100):flip(XY)}
If the Fit
parameter is specified, the formatter will keep the proportions of the image and fit it into the specified size.
For example, {{imageData}:picture(300, 300, Fit)}
. In that case, the image will be scaled down to fit into a 300 x 300 square and its aspect ratio will be preserved.
Stretch
is the default behavior and works if you only specify the dimensions. The picture takes up the defined space and it may lose its original proportions.
Let’s take a simple DOCX template and insert a picture using Power Automate, Zapier, and Make.
We’ll have this result:
Download the DOCX template and the picture
This is how the complete flow looks in Power Automate:
The DOCX template and the image reside in a SharePoint documents library. We download the files using SharePoint action Get file content.
Then we use the files with the Plumsail action Create document from DOCX template
In the template we added the tag:
{{logoImage}:picture}
to the place where we need to insert the logo.
To correctly insert the logo in the document we need to convert the SharePoint Get file content action result into base 64 code. To achieve this we can use next expression
base64(body('GetLogo'))
This is the JSON:
{
"title":"Documents logo",
"logoImage":"base64(body('GetLogo'))"
}
Also, the action saves the result document to PDF.
In Zapier, you can insert an image into your template using a Download URL output from the previous action. Check out the following steps to achieve this.
1. Set up a trigger in Zapier that captures the image you want to insert into the template. I use OneDrive trigger but it could be any other trigger like Google Drive, Dropbox, etc.
Set up the action Start Process in Plumsail Documents and use the Download URL output from the OneDrive trigger.
To insert a picture into your template in Make convert it into a base64 string with the base64 function.
For example, let’s check this scenario.
I download a source image from a OneDrive folder. Use any other connector to download the source images.
Then I add the Plumsail Documents action and select a process to start.
Next, add the base64
function.
And finally select data
from the OneDrive connector.