How to nest tables without extending the inner table?

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.



Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial
Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now