【发布时间】:2016-06-13 12:58:20
【问题描述】:
我是一名 iText Java 开发人员。我一直在使用大桌子,现在我被困在垂直拆分桌子上。
在 iText in Action 的第 119 页中,尊敬的 Bruno Lowagie(我非常尊重这个人)解释了如何拆分大表,以便列出现在两个不同的页面中。
我按照他的示例进行操作,当文档的行数很少时它可以正常工作。
在我的例子中,我有 100 行,这意味着文档需要将 100 行分成几页,同时垂直拆分列。我按如下方式运行我的代码,但只显示前 34 行。
谁能解释一下这段代码有什么问题:
//create a PDFPTable with 24 columns
PdfPTable tbl = new PdfPTable(new float{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1});
//loop through 100 rows
for (int i = 0; i < 100; i++) {
//insert 24 table cells
}
tbl.setTotalWidth(1500);//set table width
float top = document.top() - document.topMargin() - 30;
PdfContentByte canvas = writer.getDirectContent();
tbl.writeSelectedRows(0, 12, 0, -1, document.leftMargin(), top, canvas);
document.newPage();
// draw the remaining two columns on the next page
tbl.writeSelectedRows(12, -1, 0, -1, 5, top, canvas);
【问题讨论】: