简体   繁体   中英

iText nested table inside a cell

I'm creating a PDF with iText version 2.1.0. I have to create a "detail" cell in a cell of a table. I did this nesting a table inside that cell. The problem with this approach is that the borders of the nested table don't touch the borders of the container cell. What I am looking for is for a table nested inside a cell whose borders don't differenciate from the nested table borders.

I have a test like this one. I do this inside a loop to add tables inside a cell to the outer table:

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);

Thanks.

I think I finally found it:

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);

The trick here is using the table in one of the PdfPCell constructor.

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

table.setWidthPercentage(100);

As you identified,

cell.setPadding(0);

is what you needed.

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