I would like to create an invoice PDF using OpenPDF. It needs a header and footer on each page. I'm using Thymeleaf to generate the content for the pdf. My question is then how to add a header and/or footer to each page.
I have found a related post (Rectangular header and footer block on every page of PDF using OpenPDF), but then I would like the ability to define the header/footer using a html template string. Is that possible? Or would you recommend an other approach?
// create and register page event to add header and footer to each page
writer.setPageEvent(new PdfPageEventHelper() {
@Override
public void onEndPage(PdfWriter writer, Document document) {
PdfContentByte cb = writer.getDirectContent();
cb.rectangle(header); // <- header should be a html template
cb.rectangle(footer); // <- footer should be a html template
}
});