iTextSharp nested tables gotcha
January 2nd, 2008 LukeI’m working on a project right now that uses iTextSharp to generate PDF reports for something.
The reports are fairly detailed, and require that we nest some tables in order to get all of the information we need displayed properly.
In order to nest tables under iTextSharp, you can not use the Table object. You have to use the PdfPTable object..
You also need to be aware that, unlike iTextSharp’s Table object(which is apparently no longer supported), you are required to fill out rows to have them display.
That means that, if you are attempting to nest tables using iTextSharp’s PdfPTable object, you absolutely have to add cells until a row is full. For example:
PdfPTable table = new PdfPTable(2);
table.AddCell("Header 1");
table.AddCell("Header 2");
PdfPTable nested = new PdfPTable(1);
nested.AddCell("nested entry 1");
nested.AddCell("nested entry 2");
table.AddCell(nested);
table.AddCell("");
The example above is the bare minimum that you need to achieve nested tables using the PdfPTable object. If you do not have the