【问题标题】:Nested iText PdfPTable border width嵌套 iText PdfPTable 边框宽度
【发布时间】:2013-03-29 17:59:32
【问题描述】:

我正在使用 iTextPdf 生成 pdf,并且正在使用以下代码创建嵌套表。

PdfPTable table = new PdfPTable(3);
PdfPTable nestedTable = new PdfPTable(2);
table.addCell(nestedTable);

现在,我希望table 的边框宽度为 0,即不可见。我已经检查了 api 和一些关于 SO 的帖子,但我找不到任何实质性的东西。有办法吗?

我使用的是 iText 5.1.2 版

【问题讨论】:

    标签: java border itext itextpdf


    【解决方案1】:

    在 iText PDF api 中没有这样的属性来直接操作边框,但是 PdfPCell 扩展 Rectangle 它有 setBorder 来操作边框。所以我只是使用了与下面提供的解决方法相同的方法:

    PdfPTable table = new PdfPTable(2);
    PdfPTable nestedTable1 = new PdfPTable(1);
    PdfPTable nestedTable2 = new PdfPTable(1);
    
    PdfPCell cell = new PdfPCell(new Phrase("StackOverflow"));
    newCell.setBorder(Rectangle.NO_BORDER);
    
    nestedTable1.addCell(cell);
    nestedTable2.addCell(new Phrase("StackOverflow"));
    
    cellOne = new PdfPCell(nestedTable1);
    cellTwo = new PdfPCell(nestedTable2);
    
    cellOne.setBorder(Rectangle.NO_BORDER);
    
    table.addCell(cellOne);
    table.addCell(cellTwo);
    

    输出:

                                _______________________
                               |                       | 
          StackOverflow        |     StackOverflow     |
                               |_______________________|
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-24
      • 1970-01-01
      • 2014-08-18
      相关资源
      最近更新 更多