tags:

views:

1494

answers:

2

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.

+1  A: 

I think I finally found it:

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

c2 = new PdfPCell (testTable);
c2.setPadding(0);
outerTable.addCell(c2);

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

Averroes
+1  A: 

As you identified,

cell.setPadding(0);

is what you needed.

cagcowboy
Yes, but I found that doing this wayc2 = new PdfPCell();c2.addElement(testTable);c2.setPadding(0);doesn't work the same way as c2 = new PdfPCell (testTable);c2.setPadding(0);outerTable.addCell(c2);In the first case you can see the nested table borders.
Averroes