嗨,大家好,我有一個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