iText - setSplitRows issue

381 views Asked by At

I'm trying to generate iText PDF report using PdfPTable. There is an issue with table rows. I don't want to have a splitted row between two pages so I set up a table.setSplitRows(false); but one of my rows in the table has been removed (or is hidden)! I don't know why. I suspect there might be a reason related to table.setHeaderRows method because I want to repeat my header on every page. When I set setSplitRows(true) then my all my rows are visible, but if there is a row with two-line description then it is cut between two pages. Any advice?

PdfPTable table = new PdfPTable(2);
table.setHeaderRows(1);
table.setSplitRows(false);
table.addCell(new Phrase("HEADER"));
table.addCell(new Phrase("HEADER2"));
table.addCell(new Phrase("Row1-a"));
table.addCell(new Phrase("Row1-b"));
...(many rows here)...
table.addCell(new Phrase("RowN-a")); <--last row on first page (disapeared)
table.addCell(new Phrase("RowN-b")); <--last row on first page (disapeared)
table.addCell(new Phrase("RowN+1-a")); <--first row on second page
table.addCell(new Phrase("RowN+1-b")); <--first row on second page
pdfDoc.add(table);

The row marked as "last row on first page" is splitted on two pages if table.setSplitRows(true);. If table.setSplitRows(false); then this row is removed! This is only small, two-line row. What is the reason of removal this row?!

1

There are 1 answers

0
sticker On

It turned out this behaviour is intended by iText https://livebook.manning.com/book/itext-in-action-second-edition/chapter-4/157 There is information:

> Blockquote

So I had to put inner table inside every cell and prevent this table from being splitted. Outer table has been set to setSplitRow(true). This is my workaround. Heavy, but works.