在iText中将PDFPTable添加到页面底部

我正在尝试添加一个表格作为包含所有版权文本,页码等的页脚。但是我找不到任何可以接受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); 

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()


页眉/页脚示例

作为相关注释,如果您在此链接上关注示例,则“艺术”框似乎不是必需的,并且幻数36,54,559,788对应于:

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

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