2013-06-12 21 views
1

我想創建一個表有兩個單元與採取的角落,一半中段邊界: enter image description here特殊的單元格邊框在iText的

我用虛線但無濟於事發揮各地。如果有人能指出我正確的方向,那會很好。

回答

1

您需要將單元格的邊框設置爲並使用單元格事件繪製自定義邊框。你可以找到一些例子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()操作。