Table class used by iTextPdf (iText and iTextSharp) versions 5.x for generating tables
PdfPTable
is the class for creating tables in itext (Java) and itextsharp (.Net).
This is a very simple example of its use:
/**
* Example written by Bruno Lowagie and Nishanthi Grashia in answer to the following question:
* https://stackoverflow.com/questions/24359321/adding-row-to-a-table-in-pdf-using-itext
*/
@WrapToTest
public class SimpleTable
{
public static final String DEST = "results/tables/simple_table.pdf";
public static void main(String[] args) throws IOException, DocumentException
{
File file = new File(DEST);
file.getParentFile().mkdirs();
new SimpleTable().createPdf(DEST);
}
public void createPdf(String dest) throws IOException, DocumentException
{
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(dest));
document.open();
PdfPTable table = new PdfPTable(8);
for(int aw = 0; aw < 16; aw++)
{
table.addCell("hi");
}
document.add(table);
document.close();
}
}
Many more examples illustrating how to build more complex tables, can be found in the examples section of itextpdf.com.