javapdf-generationitextpdfptable

Itext LargeElement and splitRows option


I'm trying to create a pdf containing a big table with itext v5.5.3.

I need :

With the code below, everything works fine :

    Document document = new Document(PageSize.LETTER);
    PdfWriter.getInstance(document, baos);

    document.open();
    PdfPTable table = new PdfPTable(5);
    table.setHeaderRows(1);
    //table.setSplitRows(false);
    //table.setComplete(false);

    for (int i = 0; i < 5; i++) {table.addCell("Header " + i);}     

    for (int i = 0; i < 500; i++) {
        table.addCell("Test " + i);
        //if (i%5 == 0) {document.add(table);}
     }

    //table.setComplete(true);
    document.add(table);
    document.close();

If I add memory management (adding table to document every 5 cells), I'm losing first header :

    Document document = new Document(PageSize.LETTER);
    PdfWriter.getInstance(document, baos);

    document.open();
    PdfPTable table = new PdfPTable(5);
    table.setHeaderRows(1);
    //table.setSplitRows(false);
    table.setComplete(false);

    for (int i = 0; i < 5; i++) {table.addCell("Header " + i);}     

    for (int i = 0; i < 500; i++) {
        table.addCell("Test " + i);
        if (i%5 == 0) {document.add(table);}
    }

    table.setComplete(true);
    document.add(table);
    document.close();

If i add memory management + setSplitRows(false), I lose all headers and some lines :

    Document document = new Document(PageSize.LETTER);
    PdfWriter.getInstance(document, baos);

    document.open();
    PdfPTable table = new PdfPTable(5);
    table.setHeaderRows(1);
    table.setSplitRows(false);
    table.setComplete(false);

    for (int i = 0; i < 5; i++) {table.addCell("Header " + i);}     

    for (int i = 0; i < 500; i++) {
        table.addCell("Test " + i);
        if (i%5 == 0) {document.add(table);}
    }

    table.setComplete(true);
    document.add(table);
    document.close();

I've done some tests and with itext version 2.1.7.js2, all three test cases are working correctly.

So, bug or not bug ? What can I do to make this working ?

Thanks


Solution

  • This was indeed a regression, so I've added a fix for this issue to the iText library. (Revision 6630).

    It will be included in the 5.5.4 release, which is due in two-three weeks.