iText嵌套表 - 第一行未呈现 [英] iText nested table - first row not rendered

查看:146
本文介绍了iText嵌套表 - 第一行未呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在根据列表的大小生成一个表。
表格设置为适合avery表格,有 5 列和13行。

i am generating a table, based on the size of a list. The table is set up to fit on an avery form, there are 5 columns and 13 rows.

当列表大小小于5,没有显示任何内容。
如果列表大小为5或更大,则显示正确。

When the list size is smaller than 5, nothing is shown. If the list size is 5 or greater, it is shown properly.

Document doc = new Document(PageSize.A4, pageMargin, pageMargin, pageMargin, pageMargin);   
//5 rows for the table
PdfPTable table = new PdfPTable(5);

for (int i = 0; i < list.size(); i++) {

Object obj = list.get(i);
//this is the superior cell
PdfPCell cell = new PdfPCell();
cell.setFixedHeight(60.4f);

// Nested Table, table in the cell
PdfPTable nestedTable = new PdfPTable(2);
nestedTable.setWidthPercentage(100);
nestedTable.setWidths(new int[] { 24, 76 });

// First Cell in nested table
PdfPCell firstCell = new PdfPCell();
// fill cell...

// second cell in nested table
PdfPCell secondCell = new PdfPCell();
// fill cell

// put both cells into the nestedTable
nestedTable.addCell(firstCell);
nestedTable.addCell(secondCell);

// put nestedTable into superior table
cell.addElement(nestedTable);
table.addCell(cell);
}

doc.add(table);
doc.close();


推荐答案

您创建 PdfPTable 有5列。当该行完成时,即当它包含5个单元格时,iText将仅将表行写入输出文档。如果添加少于5个单元格,则永远不会刷新该行。

You create a PdfPTable with 5 columns. iText will only write a table row to the output document when that row is complete, i.e. when it contains 5 cells. If you add less than 5 cells, the row is never flushed.

您说:
如果列表大小为5或更大,则为正确显示。

这是不正确的。除非单元格的数量是5的倍数,否则最后一行将不会显示。

This is not correct. Unless the amount of cells is a multiple of 5, the last row will not be shown.

因此,您必须确保最后一行中有5个单元格。在将表格添加到文档之前,您可以使用此便捷方法轻松完成此操作: table.completeRow()

So you have to make sure there are 5 cells in the final row. You can easily do this by using this convenience method, right before adding the table to the document: table.completeRow()

这篇关于iText嵌套表 - 第一行未呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆