PDFBOX - 使用 easytable 的所有页面中的页眉

Opt*_*mus 2 java pdfbox

我正在使用 pdfbox 和 easytable https://github.com/vandeseer/easytable创建动态页面,效果很好。但我确实希望在所有页面中添加标题。我面临/尝试过以下事情。

1)建表器是在写入行之前创建的,因此我们可以创建一个完美的建表器,因为行是动态的。

2)尝试在创建表格构建器时在中间插入标题,这又不完美,因为 TableDrawer 根据行高使行足够

任何想法/帮助将不胜感激。

需要类似于此项目的输出 - https://github.com/eduardohl/Paginated-PDFBox-Table-Sample。这里唯一的问题是内容不像 easytable 那样是动态的。

phi*_*ous 5

作为@mkl 的答案及其评论的补充:在当前版本的库中,有一个自己的类可以满足这一要求。

所以你的代码基本上可以归结为:

try (final PDDocument document = new PDDocument()) {

    RepeatedHeaderTableDrawer.builder()
            .table(createTable())
            .startX(50)
            .startY(100F)
            .endY(50F) // note: if not set, table is drawn over the end of the page
            .build()
            .draw(() -> document, () -> new PDPage(PDRectangle.A4), 50f);

    document.save("your-awesome-document.pdf");
}
Run Code Online (Sandbox Code Playgroud)