iText中的特殊单元格边框

时间:2013-06-12 17:06:24

标签: itext

我想创建一个包含两个单元格的表格,这些单元格的边框是角落,一半是中间部分: enter image description here

我用虚线玩弄但无济于事。如果有人能指出我正确的方向,那就太好了。

1 个答案:

答案 0 :(得分:1)

您需要将单元格的边框设置为NO_BORDER并使用单元格事件来绘制自定义边框。您可以找到一些示例here

PressPreviews为例。它定义了以下单元格事件:

public class MyCellEvent extends PdfPCellEvent {
    public void cellLayout(PdfPCell cell, Rectangle position,
            PdfContentByte[] canvases) {
        float x1 = position.getLeft() + 2;
        float x2 = position.getRight() - 2;
        float y1 = position.getTop() - 2;
        float y2 = position.getBottom() + 2;
        PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
        canvas.rectangle(x1, y1, x2 - x1, y2 - y1);
        canvas.stroke();
    }
}

现在,如果您执行cell.setCellEvent(new MyCellEvent());,则单元格将具有自定义边框:一个略小于默认边框的矩形。

在您的情况下,您不需要rectangle()方法。您不会从位置变量获取坐标,并在一系列moveTo()lineTo()stroke()操作中使用这些坐标。

相关问题