【问题标题】:Add a PDFPTable to bottom of page in iText在 iText 的页面底部添加 PDFPTable
【发布时间】:2012-10-09 09:09:41
【问题描述】:

我正在尝试添加一个表格作为包含所有版权文本、页码等的页脚。但我找不到任何可以接受 PdfPTable 的支持方法

对于一个短语,代码如下:

ColumnText.showTextAligned(writer.getDirectContent(),
        Element.ALIGN_CENTER, new Phrase(
            String.format("%d", document.getPageNumber())),
            (document.getPageSize().getLeft() + document.getPageSize().getRight())/2,
            document.getPageSize().getBottom() + 18, 0);

【问题讨论】:

    标签: java itext


    【解决方案1】:

    PdfPTable 类有一个方法writeSelectedRows(),可用于在绝对位置添加(选择列和)行。

    例子:

    【讨论】:

      【解决方案2】:

      Bruno 发布的示例是一个很好的指针,这里是一个没有幻数的示例:

          private void writeFooterTable(PdfWriter writer, Document document, PdfPTable table) {
              final int FIRST_ROW = 0;
              final int LAST_ROW = -1;
              //Table must have absolute width set.
              if(table.getTotalWidth()==0)
                  table.setTotalWidth((document.right()-document.left())*table.getWidthPercentage()/100f);
              table.writeSelectedRows(FIRST_ROW, LAST_ROW, document.left(), document.bottom()+table.getTotalHeight(),writer.getDirectContent());
          }
      

      这将在底部的文档边距内写入 PdfPTable,与底部的任何文本重叠。如果您希望将表格写在页边空白处,请使用:document.bottom() 而不是 document.bottom()+table.getTotalHeight()


      Header/Footer Example

      作为相关说明,如果您按照此链接上的示例进行操作,“艺术”框似乎不是必需的,并且幻数 36、54、559、788 对应于:

      document.left(), document.bottom(), document.right(), document.top()
      

      【讨论】:

        【解决方案3】:

        要实现自定义页脚,您需要实现 PdfPageEventHelper

        【讨论】:

          猜你喜欢
          • 2012-11-08
          • 2013-11-18
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-05-11
          • 2021-07-18
          • 2013-09-12
          • 1970-01-01
          相关资源
          最近更新 更多