Pictures in DOCX templates

You can dynamically add images to your DOCX documents using the #picture object operation.

Let’s explore how to do this with a few examples.

Insert picture using Picture object

Insert a placeholder picture into your DOCX template.

This placeholder will be replaced with an actual image in the final document.

Inserting picture object

Next, right-click the placeholder, select ‘View Alt Text’ and add a token (e.g. imageData) that you will apply the #picture operation to:

{{#picture imageData}}
Inserting picture object

The #picture operation accepts URLs; however, the URL must be publicly accessible without any authentication requirements.

Library

To use the template shown aboev, format your JSON object like this:

{
    "imageData": "https://plumsail.com/docs/documents/v1.x/_images/plumsail-logo.png"
}

The #picture operation also supports Base64 strings as pictures. For the template to work with a Base64 image, pass the data like so:

Library
{
    "imageData": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIoAAAAyCAYAAACDHkN8AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAB3RJTUUH5AYDDA8z7aYtxwAACOdJREFUeJztnG9sE/cZx79JuByJTVKKXajjkhSnEknAFgxthKglVdaQjgotlaq9AaSplVZ4NQl4OQ3EqxVV24uJPxLbC4I0oTCYMpgWV5Q0IwTU/JkNdgjxQZy4dpwzJJc4di7nP3vh2LNjOzn77pcSdB/JSnz3u9/z2P7e83ue584uiEajUSgorEDhj+2AwtpAEYqCKNaRNtDzVxvGBiZRsVMDQ4MOFTs2kTapQADiQhHmw5gYnsLE8BT6r4+gtrkS9UdrULa5lLRpBRkhvvQI86GU53azE+0nuvG0+wfSphVkZBWEEk7bNuMN4PbZh4pY1hDEhRLiQ1n33T77EI4eN2kXFGTgR4koydy7/BizkwHSbihIhLhQgtP8svunXH7cu2wj7YaCRIgLZdozt+KYJ3fH8ej2c9KuKEiAqFACUzyEYPYcJRlFKK82RIUy7fGLHusdmVbE8gpDVCice+VlJxlFKK8uZIUiIj9JxjsyDY/9JSFvFKRAVCgTT6ZyPsYzpAjlVYSsUIZz/9A99hcEPInhsrDoOP0ALgtLzMZawGZ24i9H/p3TMcQuCnKeOQS5hZyPExtReL8A9hmXtp1WUdAayjMeM27xgelxY3er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29ZKdH4FaYjKUYSRv2Fh4CtEJeYg2SjaUo+Sg7eIzK0gD6KT2WhwEiHHNQgj1xCZkre5U9JyHUUVH8o6p4K85F71RCMQHNcQGrmGsCf7XfBioXYcB/2zs5LnUSBL3n0UAAi7vkXY24vwROyRK1TtF6Dr/5CveYVVRJJQkokucAh7ehD29CDC9iEyO4ZoMPMtkYUbt4Oq/QLU9l/LYVphFZBNKAqvN8ovVyuIQhGKgigUoSiIQhGKgigUoSiIQhGKgij+B4V7vYMAPildAAAAAElFTkSuQmCC"
}

For instructions on inserting an image file into your template using different services, check out the links below:

Insert picture using text token

You can also insert a picture just adding a text token into the DOCX template.

{{#picture imageData}}
Text token

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/9JSFvFKRAVCgTT6ZyPsYzpAjl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6JTdvBsP0LPbyEalHYBMMWZitVddhTEs6xQQqO3EZmyIfLyMSIvbYjMjJJzpPIXKNTsIja/gjSWLY8LNTsR4RwxwRAUCQCs29ZKdH4FaYjKUYSRv2Fh4CtEJeYg2SjaUo+Sg7eIzK0gD6KT2WhwEiHHNQgj1xCZkre5U9JyHUUVH8o6p4K85F71RCMQHNcQGrmGsCf7XfBioXYcB/2zs5LnUSBL3n0UAAi7vkXY24vwROyRK1TtF6Dr/5CveYVVRJJQkokucAh7ehD29CDC9iEyO4ZoMPMtkYUbt4Oq/QLU9l/LYVphFZBNKAqvN8ovVyuIQhGKgigUoSiIQhGKgigUoSiIQhGKgij+B4V7vYMAPildAAAAAElFTkSuQmCC"
}

Click on the links below to find instructions on how to insert an image file into your template using various services:

Resize, rotate and flip pictures

The #picture operation supports additional options for customizing your images. Let’s take a closer look.

Note

You can mix and match these options in one token to achieve your desired output. For instance, you can do: For example, {{#picture imageData 150 150 rotate:90 flip:XY}}

Resize

To resize images, include the width and height in the #picture operation. For example: {{#picture imageData 300 200}}.

In the token above, 300 is the width, and 200 is the height. You can opt to provide just the width, allowing the height to be automatically calculated to keep the aspect ratio: {{#picture imageData 300}}.

Rotate

You can rotate your picture by 90, 180, or 270 degrees by adding the :rotate option:

{{#picture imageData 100 rotate:90}}

This will create a 100x100 image rotated by 90 degrees.

Flip

This option flips the image horizontally and/or vertically.

Add it to the picture object in your template.

{{#picture imageData 100 flip:X}}

{{#picture imageData 100 flip:Y}}

{{#picture imageData 100 flip:XY}}

You can also combine resize, rotate, and flip options like this: {{#picture imageData 400 350 rotate:90 flip:XY}}

This will create a 400x350 picture rotated by 90 degrees and flipped both horizontally and vertically.

Insert picture using various services

Let’s take a simple DOCX template and insert a picture using Power Automate, Zapier, and Make.

The end result will look like this:

Insert picture in DOCX

Download the DOCX template and the picture that we’ll use in this example.

Power Automate

This is how the complete flow looks in Power Automate:

Power Automate flow

In this example, both the DOCX template and image are stored in a SharePoint document library. We download the files using the Get file content action from the SharePoint connector.

Power Automate flow

We’ll use the downloaded files in the Create document from DOCX template action from the Plumsail Documents connector.

Power Automate flow

In the template, we’ll add the token:

{{#picture logoImage}}

to the place where we need to insert the logo.

To ensure the logo inserts correctly, we convert the result of the Get file content action into a base64 string.

You can do this with the following expression:

base64(body('GetLogo'))

The corresponding JSON structure would look like this:

{
    "title":"Documents logo",
    "logoImage":"base64(body('GetLogo'))"
}

The output document will be created in the PDF format.

Create PDF

Zapier

In Zapier, adding an image to your template is as simple as using the Download URL output from a prior step.

Follow these easy steps:

  1. Set up a trigger in Zapier that captures the image you want to insert into the template.

We’ll use the New file trigger from OneDrive, but you can use any other trigger.

Zapier insert image
  1. Add the Start Process in Plumsail Documents action from Plumsail Documents and use the Download URL output from the OneDrive trigger.

Zapier insert image

Make

To insert a picture into your template in Make, convert it into a base64 string with the base64 function.

Let’s take a look at this scenario:

  1. We’ll download the source image from a OneDrive folder. Feel free to use any other connector to download your images.

Make insert image
  1. Next, add the Plumsail Documents action and select your process.

Make insert image
  1. Add the base64 function.

Make insert image
  1. Lastly, select data from the OneDrive connector.

Make insert image