首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在同一页pdfbox上创建多个表格?

如何在同一页pdfbox上创建多个表格?
EN

Stack Overflow用户
提问于 2021-07-13 13:02:35
回答 2查看 112关注 0票数 1

我想使用pdfbox和boxable创建多个表格(表格如下)。但是表是重叠的,我该怎么解决呢?

代码语言:javascript
复制
for(ProductGroup productGroup: productGroups) {
            BaseTable table = new BaseTable(yStart, yStartNewPage, bottomMargin, tableWidth, margin, doc, page, true, drawContent);
            Row<PDPage> headerRow = table.createRow(15f);
            Cell<PDPage> cell;
            createHeader(headerRow, table);
            Row<PDPage> row;
            for(Article article: productGroup.getArticles()) {
                row = table.createRow(10f);
                cell = row.createCell((100 / 9f) , article.getBranch().replace("\n", "").replace("\r", ""));
                cell.setFont(PDType1Font.HELVETICA);
                cell.setFontSize(fontSize10);
                cell = row.createCell((100 / 9f) , article.getMode().replace("\n", "").replace("\r", ""));
                cell.setFont(PDType1Font.HELVETICA);
                cell.setFontSize(fontSize10);
                cell = row.createCell((100 / 3f) , article.getFeatureText().replace("\n", "").replace("\r", ""));
                cell.setFont(PDType1Font.HELVETICA);
                cell.setFontSize(fontSize10); 
    }
}
EN

回答 2

Stack Overflow用户

发布于 2021-07-22 02:57:42

当您调用table.draw()时,它返回yStart坐标,即表格在当前页面上的结束位置。您可以将它用作for循环中下一个表的输入参数yStart。

例如,在您的代码片段中

代码语言:javascript
复制
float yStart = 650;//for example
for(ProductGroup productGroup: productGroups) {
            BaseTable table = new BaseTable(yStart, yStartNewPage, bottomMargin, tableWidth, margin, doc, page, true, drawContent);
            Row<PDPage> headerRow = table.createRow(15f);
            Cell<PDPage> cell;
            createHeader(headerRow, table);
            Row<PDPage> row;
            for(Article article: productGroup.getArticles()) {
                row = table.createRow(10f);
                cell = row.createCell((100 / 9f) , article.getBranch().replace("\n", "").replace("\r", ""));
                .....
            }
            //getting Yposition of table end
            yStart = table.draw();
            //As you are drawing multiple tables which might get split over pages, get the latest page
            page = document.getPage(document.getNumberOfPages()-1);

}
票数 0
EN

Stack Overflow用户

发布于 2022-01-28 18:29:06

Set,yStart = table.draw()

使用对应的yStart位置创建另一个BaseTable

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68356749

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档