在iText-5.0.1中,有没有办法用虚线(例如__ _)代替实线(例如________________ )来设置单元格的边框?
发布于 2010-03-24 19:53:42
你能做一些类似添加小高度和text=的新段落的东西吗?“-”
PdfPCell Cell = new PdfPCell(new Paragraph("------"));
Cell.Height = 0.2f;您也可以使用PdfPCellEvent自己绘制边框。有不同的层可以添加。查看这里的接口:http://api.itextpdf.com/com/itextpdf/text/pdf/PdfPCellEvent.html
发布于 2010-03-24 21:52:53
按照建议,使用PdfPCellEvent。下面的代码应该可以帮助您完成大部分工作。通过覆盖Cell event example.事件,您基本上可以告诉iText您认为它应该如何绘制其单元格。无论何时将任何单元格添加到表中,它们都将遵循您的规则。
class CustomCell implements PdfPCellEvent {
public void cellLayout(PdfPCell cell, Rectangle rect,
PdfContentByte[] canvas) {
PdfContentByte cb = canvas[PdfPTable.LINECANVAS];
cb.setLineDash(new float[] {3.0f, 3.0f}, 0);
cb.stroke();
}
}
public class Main {
public static void main(String[] args) throws Exception {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("output.pdf"));
document.open();
CustomCell border = new CustomCell();
PdfPTable table = new PdfPTable(6);
PdfPCell cell;
for (int i = 1; i <= 6; i++) {
cell = new PdfPCell(new Phrase("test"));
cell.setCellEvent(border);
table.addCell(cell);
}
document.add(table);
document.close();
}
}发布于 2014-06-02 23:41:16
带下划线的单元格:
public class UnderlinedCell implements PdfPCellEvent {
public void cellLayout(PdfPCell cell, Rectangle position,
PdfContentByte[] canvases) {
PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
canvas.setLineWidth(0.5f);
canvas.setLineDash(3f, 3f);
canvas.moveTo(position.getLeft(), position.getBottom());
canvas.lineTo(position.getRight(), position.getBottom());
canvas.stroke();
}
}https://stackoverflow.com/questions/2507291
复制相似问题