List of usage examples for com.lowagie.text.pdf PdfWriter getCurrentPageNumber
public int getCurrentPageNumber()
From source file:com.actelion.research.spiritapp.ui.util.PDFUtils.java
License:Open Source License
public static void addHeader(PdfWriter writer, String header) { class MyFooter extends PdfPageEventHelper { com.lowagie.text.Font ffont; @Override/* w w w.ja v a 2 s.co m*/ public void onEndPage(PdfWriter writer, Document document) { try { ffont = new com.lowagie.text.Font( BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED), 6f, com.lowagie.text.Font.ITALIC); } catch (Exception e) { e.printStackTrace(); return; } String date = FormatterUtils.formatDateTime(new Date()); PdfContentByte cb = writer.getDirectContent(); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase(header, ffont), document.left(), document.top() + 5, 0); ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, new Phrase("Page " + writer.getCurrentPageNumber(), ffont), (document.right() - document.left()) / 2 + document.leftMargin(), document.bottom() - 5, 0); ColumnText.showTextAligned(cb, Element.ALIGN_RIGHT, new Phrase(date, ffont), document.right(), document.bottom() - 5, 0); } } writer.setPageEvent(new MyFooter()); }