Skip to main content

Template Engines

When generating dynamic PDFs, you usually need to render HTML through a template engine first and then pass it to bkhtmltopdf for conversion. For Java development, FreeMarker is recommended (concise and efficient); Thymeleaf can also be used depending on your preference.

Typical workflow: the system generates HTML using a template engine → HTTP POST to the bkhtmltopdf API → output PDF.

FreeMarker


<html lang="en">
<head>
<title>Welcome!</title>
</head>
<body>
<h1>Welcome ${user}!</h1>
<p>Our latest product:
<a href="${latestProduct.url}">${latestProduct.name}</a>!
</body>
</html>

HTML


<html lang="en">
<head>
<title>Welcome!</title>
</head>
<body>
<h1>Welcome John Doe!</h1>
<p>Our latest product:
<a href="products/greenmouse.html">green mouse</a>!
</body>
</html>

PDF

Template Engine Output.pdf