'How to create multiple table on the same page pdfbox?

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



Solution 1:[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);

}

Solution 2:[2]

Set, yStart = table.draw()

Create another BaseTable with corresponding yStart position

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 InCh
Solution 2 SANTHOSH WEB DEVELOPER