How to nest tables without extending the inner table?

Category: 
Tags: nested tablestablesiText 7

I am using iTextSharp in a .NET project to generate a PDF file. I have a PdfPTable with two cells in one row. I put another PdfPTable in each cell: the first one has two rows; the second one has three rows. The last row of the smaller table stretches to fill the space. How can I avoid that the smaller table stretches to fit the cell of the outer table? Additionally: how do I align the inner table to the bottom?

Posted on StackOverflow on Feb 11, 2015 by lng

Please take a look at the following screen shot:

Screenshot
Screenshot

This screen shot was taken from the result of the NestedTables example. You are describing what happens when you add the table straight to another table. This is how it’s done in iText 7:

Table innerTable1 = new Table(1);
Table innerTable2 = new Table(2);
Cell cell;
innerTable1.addCell("Cell 1");
innerTable1.addCell("Cell 2");
outerTable.addCell(innerTable1);
innerTable2.addCell("Cell 3");
innerTable2.addCell("Cell 4");
outerTable.addCell(innerTable2);
cell = new Cell(1, 14);
outerTable.addCell(cell);

We use addCell() method and pass the Table instance directly to it. Note that there are no PdfPTable and PdfPCell classes anymore, you should use Table and Cell instead.

Click this link if you want to see how to answer this question in iText 5.