0
我一些問題的OnEndPage()方法(iText的),基本上我已經寫在頁腳一些文字,像這樣的方式BASC方法:如何在onEndPage()itext方法中傳遞自定義對象?
public class EventDichiarazionePdf extends PdfPageEventHelper{
private int numPage=0;
private static Font h6NormFont = new Font(Font.FontFamily.HELVETICA, 6,Font.NORMAL);
public void onStartPage(PdfWriter writer, Document document) {
numPage++;
}
public void onEndPage(PdfWriter writer, Document document) {
try {
Rectangle page = document.getPageSize();
PdfPTable footer = new PdfPTable(2);
PdfPCell cellFooter = new PdfPCell(new Phrase("Something – 03/12/2016 Customer n." + "here i need my variable",h6NormFont));
cellFooter.setHorizontalAlignment(Element.ALIGN_LEFT);
cellFooter.setBorder(0);
footer.addCell(cellFooter);
cellFooter = new PdfPCell(new Phrase(String.format("pag. %d",numPage),h6NormFont));
cellFooter.setHorizontalAlignment(Element.ALIGN_RIGHT);
cellFooter.setBorder(0);
footer.addCell(cellFooter);
footer.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
footer.writeSelectedRows(0,-1,document.leftMargin(),document.bottomMargin(),writer.getDirectContent());
} catch (Exception e) {
throw new ExceptionConverter(e);
}
}
}
}
Basicaly我想通過一個更對象加上寫入和文檔到onEndPage,但這種方法永遠不會被創建的Pdf,在文檔上閱讀,這種方法是由一個事件調用,所以我甚至不能改變我猜的方法的簽名..任何建議? 謝謝大家的答案。