嗨,大家好,我有一个java类,用于在iText PDF中显示页眉和页脚。Itext pageNumber在PDF中显示
的页码显示在页面顶部和页脚在页脚部分正确地来.. 现在我想以显示页脚处的页码...
下使用
代码IM这样1 (header)
public HeaderAndFooter() {
header = new Phrase("**** Header ****");
footer = new PdfPTable(1);
footer.setTotalWidth(130);
footer.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
footer.addCell(new Phrase(new Chunk(
"**** Footer summary****")
.setAction(new PdfAction(PdfAction.FIRSTPAGE))));
}
public void onEndPage(PdfWriter writer, Document document) {
PdfContentByte cb = writer.getDirectContent();
ColumnText.showTextAligned(cb, Element.ALIGN_RIGHT, new Phrase(String.format("%d", writer.getPageNumber()),
PDFUtil.getNormalFont()), (document
.right() - document.left())
/2 + document.leftMargin(), document.top() + 10, 0);
footer.writeSelectedRows(0, -1,
(document.right() - document.left() - 300)/2
+ document.leftMargin(), document.bottom() - 10, cb);
}
}
即时得到输出
26月 - 2011 Rentaldetails月----5500个月
杂---- 500 总--- 5500
**** Footer summary (footer)
****
好心建议我如何显示页脚部分编号和副... Thankxxx提前
什么版本的IText?老版本有HeaderFooter对象 – Sean
@Sean Am使用iText.2.1.0 – Aravinth
用writer.getPageNumber()输出的短语是什么?如果它是空白的,请尝试在其周围添加一些文字,以查看是否可能存在其他问题。这是获取页码的呼叫。你应该能够相应地进行格式化 – Sean