alebo611
alebo611

Reputation: 1280

How to achieve space between columns in itext 7 tables?

I need to achieve a table that looks like the one in the picure, with space between columns. I tried:

    cell.setPaddingLeft(10);
    cell.setMarginLeft(10);
    extractionMediaTable.setVerticalBorderSpacing(10);

But none of these seem to affect the table. Any suggestions?

enter image description here

Upvotes: 2

Views: 3838

Answers (1)

Uladzimir Asipchuk
Uladzimir Asipchuk

Reputation: 2478

This should help:

    table.setBorderCollapse(BorderCollapsePropertyValue.SEPARATE);
    table.setVerticalBorderSpacing(10);
    table.setHorizontalBorderSpacing(10);

Some explanations: By default iText creates tables with collapsed borders, so the first line overrides that. Once the borders are separated, one can set the spacing (either horizontal or vertical) between them.

For example, look at the snippet below and the screenshot of the resultant pdf:

    Table table = new Table(3);
    table.setBorderCollapse(BorderCollapsePropertyValue.SEPARATE);
    table.setVerticalBorderSpacing(10);
    table.setHorizontalBorderSpacing(10);

    for (int j = 0; j < 10; j++) {
        for (int i = 0; i < 3; i++) {
            table.addCell(new Cell().add(new Paragraph("Cell row " + j + "col " + i )));
        }
    }

enter image description here

Upvotes: 6

Related Questions