简体   繁体   English

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

[英]How to create multiple table on the same page pdfbox?

I want to create multiple table(table below table) using pdfbox and boxable.我想使用 pdfbox 和 boxable 创建多个表(表下方的表)。 but table just overlap, how do I solve it?但表只是重叠,我该如何解决?

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); 
    }
}

When you call table.draw() it returns yStart coordinate ie where the table ends on the current page.当您调用table.draw()它返回 yStart 坐标,即表格在当前页面上的结束位置。 You can use it as a input parameter yStart for your next table in for loop.您可以将其用作 for 循环中下一个表的输入参数 yStart。
For example in your code snippet例如在您的代码片段中

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);

}

Set, yStart = table.draw()设置,yStart = table.draw()

Create another BaseTable with corresponding yStart position创建另一个具有相应 yStart 位置的 BaseTable

"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM