简体   繁体   中英

Last row on the first page in iText table isn't drawing border at baseline of the font like all the other rows when table is split across pages

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.

第一页最后一行的图像未在字体的底部绘制

这是预期的行为,并且iText当前不支持这种极端情况。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM