我正在尝试添加一个表格作为页脚,其中包含所有版权文本,页码等.但我找不到任何支持方法,即接受一个 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);
Run Code Online (Sandbox Code Playgroud)
的PdfPTable类有一个方法writeSelectedRows()可以被用于添加在绝对位置(选择列和的)行.
例子:
ColumnText对象中的替代解决方案.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());
}
Run Code Online (Sandbox Code Playgroud)
这将在底部的文档边距内写入PdfPTable,与底部的任何文本重叠.如果您希望在边距中写表,请使用:document.bottom()而不是document.bottom()+table.getTotalHeight().
作为相关注释,如果您在此链接上关注示例,则"艺术"框似乎不是必需的,并且幻数36,54,559,788对应于:
document.left(), document.bottom(), document.right(), document.top()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12851 次 |
| 最近记录: |