我需要实现一个看起来像图片中的表,列之间有空格。我试过了:
cell.setPaddingLeft(10);
cell.setMarginLeft(10);
extractionMediaTable.setVerticalBorderSpacing(10);
但这些似乎都没有影响到桌子。有什么建议?
这应该有所帮助:
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 )));
}
}