2016-03-02 316 views

回答

0

請看看CellTitle的例子。它創造了其標題是在單元格邊框增加了PDF:cell_title.pdf

enter image description here

這是通過使用完成了cell event

class Title implements PdfPCellEvent { 
    protected String title; 

    public Title(String title) { 
     this.title = title; 
    } 

    public void cellLayout(PdfPCell cell, Rectangle position, 
     PdfContentByte[] canvases) { 
     Chunk c = new Chunk(title); 
     c.setBackground(BaseColor.LIGHT_GRAY); 
     PdfContentByte canvas = canvases[PdfPTable.TEXTCANVAS]; 
     ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, 
      new Phrase(c), position.getLeft(5), position.getTop(5), 0); 
    } 
} 

小區事件可以使用被添加到PdfPCellsetCellEvent()方法:

public PdfPCell getCell(String content, String title) { 
    PdfPCell cell = new PdfPCell(new Phrase(content)); 
    cell.setCellEvent(new Title(title)); 
    cell.setPadding(5); 
    return cell; 
} 

下次,請在提出問題之前顯示您嘗試過的內容。另外請看official documentation,因爲您需要自己回答您的問題的所有內容都可以在iText網站上找到。