2

I want to create multiple table(table below table) using pdfbox and 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); 
    }
}

kalipts
  • 1,097
  • 1
  • 9
  • 21
  • You should update `yStart` each time after drawing a table to a position underneath that previous table. – mkl Jul 13 '21 at 07:40

2 Answers2

1

When you call table.draw() it returns yStart coordinate i.e. where the table ends on the current page. You can use it as a input parameter yStart for your next table in for loop.
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);

}
InCh
  • 529
  • 1
  • 5
  • 18
0

Set, yStart = table.draw()

Create another BaseTable with corresponding yStart position