In DocuGenerate, not only can you create dynamic text content, but you can also add dynamic images to your templates. This feature enables you to personalize your documents even further by including unique images based on your data source. The accepted image formats are PNG, JPEG and SVG.
To add an image to your template, use a tag starting with %
, like for example [%image]
, [%logo]
or [%user.profile_picture]
. Let’s consider the following template:
Company logo
[%logo]
Your JSON data should contain a logo
field which points to the URL of the image. Ensure that the JSON key doesn’t include the %
character, as it needs to be "logo"
and not "%logo"
:
[{
"logo": "https://www.docugenerate.com/assets/images/logo/docugenerate.png"
}]
When the template is processed, DocuGenerate replaces the [%logo]
tag with the actual image fetched from the specified URL. The result should look like this:
If for whatever reason the image cannot be fetched and the request to get the image is unsuccessful, then the image will simply be ignored when the document is generated.
The image you provide can also be encoded in Base64 format. In this case, you need to convert the image to Base64 on your side before using it in your template.
This is a smiley
[%image]
For this example, your JSON data should look as follows. Make sure the JSON key doesn’t include the %
character, as it needs to be "image"
and not "%image"
:
[{
"image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAKqWlDQ1BJQ0MgUHJvZmlsZQAASImVlwdUU+kSgP97bzoJLSHSCb1JbwGkhNBC781GSAKEEkIgKNiRxRVcCyoi2EBXQBRcCyCLDVFsi2LvC7KIKOtiwYbKu8AhuPvOe++8OWfOfJnMPzP/f+5/z1wAKIpcsTgDVgQgU5QrifDzYsTFJzDwgwABNEABSmA2l5cjZoWFBQFUpu3f5f0dAE3YmxYTuf79//8qSnxBDg8AKAzlJH4OLxPlY6i+4IkluQAge1C//qJc8QR3okyToA2ifG+CU6Z4eIKTJhkDJmOiItgo0wAgkLlcSQoAZAbqZ+TxUtA8ZE+UrUV8oQhlMcrumZlZfJQPo2yCxqA+8kR+ZtJ3eVL+ljNJlpPLTZHx1F4mheAtzBFncPP/z+P435KZIZ2uYYQqOVXiH4FaZfTM7qVnBcpYlBQSOs1C/mT8JKdK/aOnmZfDTphmPtc7ULY2IyRompOFvhxZnlxO1DQLcnwip1mSFSGrlSxhs6aZK5mpK02Pl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xdC9KwUiwyllOPm8+pIBNiCbYagXPCN6VUJ6p4kquio89uQS93TFYUzYwU5bTk03NPdtfJZT6cUsA4ZLLex5enehQj4vGCCIEcf5cAX/54xiMkot00qToVB4RzBmrKwRjsQpyJR/x9hjWfKoHHY0a3BzvDKVZ5EfFPV1PDp6qdz3334IAwumxPdv6M63+34J0Uok2GZh1JWu7jMsXSrDybDgUXdjlNKrczJpY1JtEF6OOuAJWgQdVsWBfm9BXLf7CgX/eynn47gMBhAuGXnks05PN79MaU/eb6RjUpAaPjcpyJBxGzlbAq5gOnSehxjKziwRWrDJ6Z59XzWzPPrE3bJsLjtsCCHeGqR7/1WdXxjKFXWZS2cC2CCTMueOXHVCyx8uqxUNrFnbJ2FcoJr7Zu/23Zxf0Om/ijgDMWw9eWmLN6cJyU1SWabrd7Ulh+VKftF3znUtOcuzjT/+CV6EPx/8RA/8GZqppwnTTJn8AAAAASUVORK5CYII="
}]
In the JSON data, the image
field includes a Base64-encoded string that represents the image. When the template is processed, DocuGenerate replaces the [%image]
tag with the actual image as defined in the Base64 string. The result should look like this:
Please note that the size of the Base64-encoded string impacts the size of the JSON data. Be cautious about using large or high-resolution images, as these can significantly increase the size of your JSON data.
By default, images are added to the template using their original dimensions. However, you can customize the image size using the following syntax, but you need to enable the enhanced syntax for your template:
[%image | size:'width':'height']
The width
value is an integer representing the image width in pixels. You can also use 'auto'
to determine the width automatically based on the image height, while keeping the aspect ratio of the image.
The height
value is an integer representing the image height in pixels. Similarly, you can use 'auto'
to determine the height automatically based on the image width, while keeping the aspect ratio of the image.
Examples:
[%image | size:200:100]
[%image | size:200:'auto']
[%image | size:'auto':100]
These examples demonstrate how to set specific dimensions or utilize automatic scaling for either width or height.