【发布时间】:2016-03-02 12:01:56
【问题描述】:
【问题讨论】:
标签: android itextpdf pdfptable
【问题讨论】:
标签: android itextpdf pdfptable
请查看CellTitle 示例。它会创建一个 PDF,其中在单元格边框上添加了标题:cell_title.pdf
这是通过使用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);
}
}
可以使用setCellEvent() 方法将单元格事件添加到PdfPCell:
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 网站上找到。
【讨论】: