9

我正在使用 iText 2.1.0 版创建 PDF。我必须在表格的单元格中创建一个“详细信息”单元格。我这样做是在该单元格内嵌套一个表格。这种方法的问题是嵌套表格的边界不接触容器单元格的边界。我正在寻找的是嵌套在单元格内的表格,其边框与嵌套表格边框没有区别。

我有一个像这样的测试。我在循环中执行此操作以将单元格内的表格添加到外部表格:

PdfPCell testCell = new PdfPCell(new Paragraph("Test"));
//I want this border to touch the containerCell borders.
testCell.setBorder(PdfPCell.BOTTOM);
testTable =  new PdfPTable(2);

testTable.addCell(testCell);
testTable.addCell(testCell);
testTable.addCell(testCell);
testTable.addCell(testCell);

PdfPCell containerCell = new PdfPCell();
containerCell.addElement(testTable);
outerTable.addCell(containerCell);

谢谢。

4

3 回答 3

22

我想我终于找到了:

testTable = new PdfPTable(1);
PdfPCell c2;
testTable.addCell("aaaa");
testTable.addCell("bbbb");

c2 = new PdfPCell (testTable);//this line made the difference
c2.setPadding(0);
outerTable.addCell(c2);

这里的技巧是在 PdfPCell 构造函数之一中使用该表。

于 2009-08-27T12:52:52.170 回答
4

我发现导致我的表格小于封闭单元格的原因是我没有将以下代码添加到表格中:

table.setWidthPercentage(100);
于 2012-07-30T18:36:02.123 回答
2

正如你所确定的,

cell.setPadding(0);

是你需要的。

于 2009-08-27T21:05:00.917 回答