I have an example below that generates a table with ten rows, the last row taking up two lines. The document height is two points smaller than it needs to be to correctly fit the entire table. As expected the last row on the first page contains the word "Two" and the "Lines" portion continues on another page. The generated PDF, however, extends the last row to fit the entire document, excluding page margin padding, instead of using the height of the text in the last row to determine how high it should be. Note that I use table.setExtendLastRow(false, false)
to guarantee that the table shouldn't be extended, and yet the last row is getting extended anyway. Any ideas how to stop the last row from being extended?
FileOutputStream out = new FileOutputStream(new File("table.pdf"));
Document document = new Document(new Rectangle(612, 242));
PdfWriter.getInstance(document, out);
document.open();
PdfPTable table = new PdfPTable(1);
table.setWidthPercentage(100);
table.setSplitLate(false);
table.setSplitRows(true);
table.setExtendLastRow(false, false);
for (int i = 0; i < 10; i++) {
PdfPCell cell;
if (i == 9) {
cell = new PdfPCell(new Phrase("Two\nLines"));
}
else {
cell = new PdfPCell(new Phrase(Integer.toString(i)));
}
table.addCell(cell);
}
document.add(table);
document.close();
I've uploaded a picture of what I'm seeing. Notice the spacing under the word "Two" is different than the spacing under all the other numbers in the rows. It appears to extend to the bottom of the page margin.
This is expected behavior and iText doesn't currently have support for this edge case.