我需要实现一张看起来像图中的桌子,并且在列之间留有间隔。我尝试过:
cell.setPaddingLeft(10);
cell.setMarginLeft(10);
extractionMediaTable.setVerticalBorderSpacing(10);
但是这些似乎都不影响表。有什么建议吗?
答案 0 :(得分:3)
这应该有帮助:
table.setBorderCollapse(BorderCollapsePropertyValue.SEPARATE);
table.setVerticalBorderSpacing(10);
table.setHorizontalBorderSpacing(10);
一些解释: 默认情况下,iText创建具有折叠边框的表,因此第一行将其覆盖。 一旦边界分开,就可以设置它们之间的间距(水平或垂直)。
例如,查看下面的代码片段和生成的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 )));
}
}