我使用下面的代码在itext 5.1.0
虚线单元事件的类
public class DottedCell implements PdfCellEvent {
public void cellLayout(PdfPCell cell,Rectangle position,PdfContentByte[] canvas) {
PdfContentByte cb=canvas[PdfPTable.LineCanvas];
cb.beginText();
cb.setLineDash(1.0f,1.0f,2);
cb.stroke();
cb.endText();
}
}
我以前用过的课程
Class PdfExample {
public static final String dest="";//address of destination
public static PdfContentbyte=cb;
public static void main(String args[]) {
Document document new Document(new Rectangle(792f,634f));
PdfWriter writer=PdfWriter.getInstance(document,new FileOutputStream(dest));
ByteArrayOutputstream baos=new ByteArrayOutputStream();
document.open();
PdfPTable table =new PdfPTable();
PdfPCell cell=new PdfPCell();
cell.setPhrase("hello pdf");
DottedCell dottedCell=new DottedCell();
cell.setEvent(dottedCell);
table.addCell(cell);
document.add(table);
}
}
在此示例中,虚线边框单元格在浏览器和文档查看器中显示为完美。