itext Tables: iText 5 versus iText 7 (iText 7)


In this example, we'll create the following table using iText 7:

enter image description here

We'll need the Table and Cell class to achieve this:

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    try (Document document = new Document(pdf)) {
        Table table = new Table(3);
        Cell cell = new Cell(1, 3)
            .add("Cell with colspan 3");
        cell = new Cell(2, 1)
            .add("Cell with rowspan 2")
        table.addCell("Cell 1.1");
        table.addCell(new Cell().add("Cell 1.2"));
        table.addCell(new Cell()
            .add("Cell 2.1")
        table.addCell(new Cell()
            .add("Cell 1.2")

Source: and the iText 7: Building Blocks tutorial.