我需要制作一张看起来像图片中的表格,列之间有空间。我试过:
cell.setPaddingLeft(10);
cell.setMarginLeft(10);
extractionMediaTable.setVerticalBorderSpacing(10);
Run Code Online (Sandbox Code Playgroud)
但这些似乎都不会影响桌子。有什么建议?
这应该有帮助:
table.setBorderCollapse(BorderCollapsePropertyValue.SEPARATE);
table.setVerticalBorderSpacing(10);
table.setHorizontalBorderSpacing(10);
Run Code Online (Sandbox Code Playgroud)
一些解释:默认情况下,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 )));
}
}
Run Code Online (Sandbox Code Playgroud)