Search code examples
javaitext7

iText 7 (Java) When Large Table extend to next page it does not draw bottom border


In my report generation java application with iText 7, I need to get data from a large data tables which may extend to several pages.

My code segments to generate the table.

    Table table = new Table(new float[] {0.4f, 1f, 1f, 1f, 1.3f, 1f, 1.3f, 0.6f,0.6f,1.2f}, true)
                .setWidth(UnitValue.createPercentValue(100))
                .setMarginTop(tblTopMargin)
                .setMarginBottom(0);
    int count = 0;
    while (!dataList.empty()) {
        String[] dataRow = dataList.poll();
        createDataRow(dataRow, table);
        count++;
        if(count % 10 == 0) {
            table.flush();
        }
    }

implementation of createDataRaw method is mentioned below,

private void createDataRow(String[] a, Table table) {
    for (String s : a) {

      Paragraph content = new Paragraph(s)
        .setFontSize(7)
        .setFixedLeading(9)
        .setFontColor(new DeviceCmyk(0, 0, 0, 100));

      Cell cell = new Cell()
        .setBorder(new SolidBorder(ColorConstants.BLACK, 0.5f))
        .setPaddingLeft(2)
        .setPaddingTop(0)
        .setPaddingBottom(0)
        .setHorizontalAlignment(HorizontalAlignment.LEFT)
        .setVerticalAlignment(VerticalAlignment.MIDDLE)
        .add(content);

      table.addCell(cell);
    }
  }

with the given code table generated with all the data. But when there is a page break between tables then the bottom line of the table is not showing except for the last table bottom.

screenshots are attached here to get a more clear idea.

enter image description here

Can someone help me to solve this issue?


Solution

  • The following code produces the desired result for me for the latest 7.1.16 version of iText:

    
        Table table = new Table(new float[] {0.4f, 1f, 1f}, true)
                .setWidth(UnitValue.createPercentValue(100))
                .setMarginBottom(0);
        document.add(table);
        int count = 0;
        for (int i = 0; i < 300; i++) {
            String[] dataRow = new String[] {"1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "2\n3\nsf\n43", "3\nr\nsdfsd\n43"};
            createDataRow(dataRow, table);
            count++;
            if (count % 10 == 0) {
                table.flush();
            }
        }
        table.complete();
    
        document.close();
    
        private void createDataRow(String[] a, Table table) {
            for (String s : a) {
                Paragraph content = new Paragraph(s)
                        .setFontSize(7)
                        .setFixedLeading(9)
                        .setFontColor(new DeviceCmyk(0, 0, 0, 100));
    
                Cell cell = new Cell()
                        .setBorder(new SolidBorder(ColorConstants.BLACK, 0.5f))
                        .setPaddingLeft(2)
                        .setPaddingTop(0)
                        .setPaddingBottom(0)
                        .setHorizontalAlignment(HorizontalAlignment.LEFT)
                        .setVerticalAlignment(VerticalAlignment.MIDDLE)
                        .add(content);
    
                table.addCell(cell);
            }
        }
    

    Visual result (end of first page):

    result