首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iText-5.0.1 +使用虚线设置PdfPTable的边框

iText-5.0.1 +使用虚线设置PdfPTable的边框
EN

Stack Overflow用户
提问于 2010-03-24 19:44:11
回答 4查看 9.9K关注 0票数 1

在iText-5.0.1中,有没有办法用虚线(例如__ _)代替实线(例如________________ )来设置单元格的边框?

EN

回答 4

Stack Overflow用户

发布于 2010-03-24 19:53:42

你能做一些类似添加小高度和text=的新段落的东西吗?“-”

代码语言:javascript
复制
PdfPCell Cell = new PdfPCell(new Paragraph("------"));
Cell.Height = 0.2f;

您也可以使用PdfPCellEvent自己绘制边框。有不同的层可以添加。查看这里的接口:http://api.itextpdf.com/com/itextpdf/text/pdf/PdfPCellEvent.html

票数 1
EN

Stack Overflow用户

发布于 2010-03-24 21:52:53

按照建议,使用PdfPCellEvent。下面的代码应该可以帮助您完成大部分工作。通过覆盖Cell event example.事件,您基本上可以告诉iText您认为它应该如何绘制其单元格。无论何时将任何单元格添加到表中,它们都将遵循您的规则。

代码语言:javascript
复制
 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();
     }
}
票数 1
EN

Stack Overflow用户

发布于 2014-06-02 23:41:16

带下划线的单元格:

代码语言:javascript
复制
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();
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2507291

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档