HTML-to-PDF for Java — write a typed PdfDocument (template + vars, page size/margins, headers, footers, page numbers) and get bytes. Agnostic of both the templating engine and the PDF engine. Based on pdf-utils, rebuilt as a navaja with everything learned in mailable-toolkit.
byte[] pdf = Pdf.generate(new InvoicePdf(invoice));Modules
- pdf-toolkit-core — pure Java (slf4j only):
PdfDocument/PdfSpec, page layout →@pageCSS, theTemplateRenderer/PdfEngine/PdfPostProcessorSPIs, andPdfGenerator. No Spring, no PDF library. - pdf-toolkit-pebble (default) / -thymeleaf / -freemarker —
TemplateRendereradapters (inheritance + inline + HTML-escape). - pdf-toolkit-openhtmltopdf — the default
PdfEngine(OpenHTMLtoPDF / PDFBox), the enginepdf-utilsused. - pdf-toolkit-spring — Spring Boot starter:
pdf-toolkit.*config, engine auto-selection, the staticPdffacade.
Design
- Templating is optional and pluggable — a
PdfSpeccarrying finalhtmlskips it entirely (no engine on the classpath needed);inlineHtmlrenders a DB-stored template string;templateresolves a named template with inheritance. - The HTML-to-PDF engine is pluggable behind
PdfEngine; the core imports no PDF library. - Generation, not document processing — encrypt / watermark / merge / sign are
PdfPostProcessorbeans contributed by the app (same boundary as mailable-toolkit). 21 tests green; decisions indocs/adr.
Install (JitPack)
<dependency>
<groupId>com.github.calcifux.pdf-toolkit</groupId>
<artifactId>pdf-toolkit-spring</artifactId>
<version>v0.1.0</version>
</dependency>
<dependency>
<groupId>com.github.calcifux.pdf-toolkit</groupId>
<artifactId>pdf-toolkit-openhtmltopdf</artifactId>
<version>v0.1.0</version>
</dependency>