如何在itext 7表中实现列之间的空间?

问题描述 投票:1回答:1

我需要实现一个看起来像图片中的表,列之间有空格。我试过了:

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

但这些似乎都没有影响到桌子。有什么建议?

enter image description here

itext itext7
1个回答
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 )));
        }
    }

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.