1. Introduction
APITemplate.io supports dynamic HTML to PDF conversion from a reusable template with a simple API.
Headers and footers are useful to include information that you want to show on every page. With APITemplate.io, it’s possible to add dynamic text, images, page numbers to the headers and footers of the generated PDF documents.
In this tutorial, we will walk you through the steps of how to add a custom HTML header, footer, and SVG logo to your generated PDF documents.
The first step is to create an HTML template for your PDF first. Then, navigate to Settings
2. Settings and Custom Header
We support custom header with HTML. To override the default header, in the HTML template, just navigate to “Settings” and then “Custom Header”
The header can be used along with Jinja2. you can include dynamic variables by using the format {{json_property}} .
Additionally, we also support dynamic values for date, title, URL, page number, total pages. To use them, you have to have a valid HTML markup with the following classes and the template engine will inject printing values into them.
3. Custom Image In Header/Footer
There are 3 ways to include an image in the header/footer:
Option 1: Use an external image
Option 2: Embed a SVG image
Option 3: Convert your logo to base64
Option 1: Use an external image
Our header and footer support external images, the following is the HTML snippet for the header/footer.
of
Option 2: Embed an SVG image
Optionally, you can use an SVG tag in the header/footer
{{batchNumber}} REV {{revision}}
{{header_title}}
The output of the PDF can be downloaded here
Option 3: Convert your logo to base64
If you do not want to use an external image, you can use embed an image using a base64 image. The following is a website that offers the conversion
Remember to optimize the size of the image before converting it to a base64 image.
The following is a snippet of HTML code for the header. You need to replace the string in the src property of the image with the base64 image.
{{batchNumber}} REV {{revision}}
{{header_title}}
4. Custom Font for Header/Footer
To load a custom font, we have to use the “custom-font” tag. Currently, we only support true type font(TTF) format. The following is the snippet to load an external TTF font.
of
To find the font-family name, visit fontdrop.info
5. Background Color for Header/Footer
To use background color in the footer and header, use the `-webkit-print-color-adjust` property to force rendering of exact colors.
of