Skip to main content

Footer

In many scenarios, adding a footer is required. bkhtmltopdf, based on Chromium, supports custom footer templates.

Chromium predefined variables can be used in the template:

VariableDescription
pageNumberCurrent page number
totalPagesTotal number of pages

Example Template


<div style="width: 100%;font-size: 20px;position: absolute;bottom: 0;text-align: center;color: white">
<span class="pageNumber"></span> of <span class="totalPages"></span>
</div>

Usage

Configure footerTemplate and displayHeaderFooter: true in the pdf object within your API request. See the HTML to PDF documentation for details.

curl 'http://localhost:8080/html-to-pdf' \
-H 'Content-Type: application/json' \
--data-raw $'{"html":"<html><body style=\'background:darkgreen;color:white;\'><h1>Hi, bkhtmltopdf.</h1></body></html>","pdf":{"headerTemplate":"<div style=\\"width: 100%;font-size: 20px;position: absolute;bottom: 0;text-align: center;color: white\\"><span class=\\"pageNumber\\"></span> of <span class=\\"totalPages\\"></span></div>","displayHeaderFooter":true}}' \
--output bkhtmltopdf.pdf

Header example