Including images in your documents

Including an image as data-uri

The data-uri format is a way to provide a complete image without requiring any HTTP request.

Static image

You can inline an image in your Template by defining its source as data-uri:
HTML
1
<img src="data:image/png;base64,R0lGODlhE...UjIQA7" />
Copied!

Dynamic image

If you send your images as data-uri:
1
{
2
"imageUrl": "data:image/png;base64,R0lGODlhE...UjIQA7"
3
}
Copied!
you can then use it in your HTML:
1
<img src="{{imageUrl}}" />
Copied!

Including an image from URL

Paid account only
Including images based on their URL is only possible on a paid account. Documents including external images will fail on a free account.

Static image

To get an image included in your Document you can define an img tag:
1
<img src="https://placekitten.com/200/300" />
Copied!

Dynamic image

If you pass the URL of an image in your data, you can then use it as source of an image in your Template.
Let's say your data looks like this:
CSS
1
{
2
"imageUrl": "http://placekitten.com/200/300"
3
}
Copied!
Using it in your Template would look like this:
HTML
1
<img src="{{imageUrl}}" />
Copied!

Using a background

You can define a background image in the CSS tab:
CSS
1
.some-class {
2
background-image: url("https://placekitten.com/200/300");
3
}
Copied!
and then apply it to any element in your HTML tab:
HTML
1
<div class="some-class">
2
...
3
</div>
Copied!

Using a dynamic background

You can't call dynamic data from the CSS tab like you do in the HTML tab. But you can do two things to use an URL from the data as source of a background.
You can use inline styling:
HTML
1
<div style="background-image: url('{{imageUrl}}');">
2
...
3
</div>
Copied!
Or you can use inlined CSS
CSS
1
.some-class {
2
background-image: url(var(--some-class-bg));
3
}
Copied!
HTML
1
<style>
2
.some-class {
3
background-image: url('{{imageUrl}}');
4
}
5
</style>
6
7
<div class="some-class">
8
...
9
</div>l
Copied!
You could also use the CSS custom properties technique if you want to keep all you CSS in the CSS tab.

Using SVG images

Another way to use images in your Document is to use inlined SVG. You can do so by inserting the code of a SVG image in your HTML:
HTML
1
<svg height="100" width="100">
2
<circle cx="50" cy="50" r="40" stroke="purple" stroke-width="3" fill="pink" />
3
</svg>
Copied!

Performance concerns

Image size

If you're concerned about the time it takes to generate your PDF, using smaller image is a very good start. The smaller the images, the faster they are to load and thus, the faster your Document generation will be.
Our recommendation is to favor formats that provide small images. PDFMonkey supports recent image formats like Webp and AVIF. You can find free image converters online that can help you get smaller images without sacrificing quality.
Another good idea is using inlined SVG or data-uri images as they will not need to load. But even for those cases, optimizing the images will be beneficial.
If you wish to keep using more classic formats like JPEG or PNG, our recommendation is to use a tool like ImageOptim to get smaller images.