简体   繁体   English

iText表中第一页的最后一行不像在表格跨页拆分时的所有其他行一样在字体的基线处绘制边框

[英]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. 正如预期的那样,第一页的最后一行包含单词“ Two”,“ Lines”部分在另一页上继续。 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. 但是,生成的PDF会扩展最后一行以适合整个文档(不包括页边距填充),而不是使用最后一行中的文本高度来确定其高度。 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. 请注意,我使用table.setExtendLastRow(false, false)来保证不应该扩展该表,但是最后一行仍在扩展。 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. 请注意,单词“ Two”下的间距不同于行中所有其他数字下的间距。 It appears to extend to the bottom of the page margin. 它似乎延伸到页边距的底部。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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