OpenPDF を使用して請求書 PDF を作成したいと考えています。各ページにヘッダーとフッターが必要です。Thymeleaf を使用して、pdf のコンテンツを生成しています。私の質問は、各ページにヘッダーやフッターを追加する方法です。
関連する投稿 ( OpenPDF を使用して PDF のすべてのページに Rectangular header and footer block ) を見つけましたが、html テンプレート文字列を使用してヘッダー/フッターを定義する機能が必要です。それは可能ですか?または、他のアプローチをお勧めしますか?
// 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
}
});