Reputation: 1280
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?
Upvotes: 2
Views: 3838
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 )));
}
}
Upvotes: 6