2016-03-02 317 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网站上找到。