4

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?

Alexey Subach
  • 11,903
  • 7
  • 34
  • 60
Vikum Dheemantha
  • 764
  • 8
  • 24

1 Answers1

0

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

Alexey Subach
  • 11,903
  • 7
  • 34
  • 60
  • 1
    What is the difference here? I did not see any difference. – Vikum Dheemantha Sep 16 '21 at 09:11
  • Difference in code? You can use an online tool to check the difference or go line by line. Does this work on your end? – Alexey Subach Sep 16 '21 at 17:05
  • @AlexeySubach you must be fun at parties... I did use a diff tool: https://www.diffchecker.com/hJI60DT2 And basically is just using different data, this is not the answer to OP question. I'm facing a similar issue but in my case is the top border on the next page that is not drawn. – RASMiranda Oct 14 '22 at 11:34