pdf - 使用 OpenPDF 在 PDF 的每一页上的页眉和页脚块
问题描述
我想使用 OpenPDF 创建发票 PDF。它需要在每一页上都有页眉和页脚。我正在使用 Thymeleaf 生成 pdf 的内容。然后我的问题是如何为每个页面添加页眉和/或页脚。
我找到了一个相关的帖子(使用 OpenPDF 在 PDF 的每一页上的矩形页眉和页脚块),但是我希望能够使用 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
}
});
解决方案
推荐阅读
- javascript - 将 div 与可点击翻转卡的底部对齐(引导程序 4)
- java - 在我的聊天应用程序中,我有这个错误 java.lang.NullPointerException
- javascript - React, Redux, TypeError: undefined is not an object, if 语句
- go - 多次运行同一个 go 程序会引发恐慌:在关闭的通道上发送
- node.js - 在继续之前等待 async.each 通过 await 完成
- postgresql - 将数据库插入带有额外列的新数据库
- asp.net-mvc - .NET Core 3.1 MVC Web 应用程序 - 访问 AzureADB2C 令牌
- ios - Info.plist 中的 UIRequiredDeviceCapabilities 键设置为应用程序不会安装在 iPad 上
- java - 我手机中的这个应用商店笔记在它第一次运行时运行它,然后我单击添加按钮并且应用程序崩溃。从手机加载应用程序数据的问题
- json - 如何读取包含许多下级的 pandas 数据帧复杂 JSON 文件