我想使用pdfbox和boxable创建多个表格(表格如下)。但是表是重叠的,我该怎么解决呢?
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);
}
}发布于 2021-07-22 02:57:42
当您调用table.draw()时,它返回yStart坐标,即表格在当前页面上的结束位置。您可以将它用作for循环中下一个表的输入参数yStart。
例如,在您的代码片段中
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);
}发布于 2022-01-28 18:29:06
Set,yStart = table.draw()
使用对应的yStart位置创建另一个BaseTable
https://stackoverflow.com/questions/68356749
复制相似问题