We are using Itext for generating the PDF's in our web application. The PDF's are getting generated properly.
I need to show some copyright information in the footer along with page numbers. I need to show the copyright information on the left hand side at the bottom while the page numbers on the right hand side at the bottom.
I have gone through google and some articles, using them I could add footer at the bottom. But this footer displays only copyright at the right hand side in the bottom.
How can I add page numbers to this using Itext?
Below is the code I am using to generate the copyright information on the right hand side at the footer.
static class HeaderFooter extends PdfPageEventHelper {
public void onEndPage(PdfWriter writer, Document document) {
Rectangle rect = writer.getBoxSize("footer");
BaseFont bf_times;
try {
bf_times = BaseFont.createFont(BaseFont.TIMES_ROMAN, "Cp1252",
false);
Font font = new Font(bf_times, 9);
ColumnText.showTextAligned(writer.getDirectContent(),
Element.ALIGN_LEFT, new Phrase("Copyright 2011",
font), (rect.getLeft() + rect.getRight()) / 2,
rect.getBottom() - 18, 0);
} catch (DocumentException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
As well below is the code which is used to show the page numbers. I am unable to combine both of these to show the page numbers and the copyright information at the same time.
ColumnText.showTextAligned(writer.getDirectContent(),
Element.ALIGN_RIGHT,
new Phrase(String.format("%d", writer.getPageNumber()),
font), (rect.getLeft() + rect.getRight()) / 2,
rect.getBottom() - 18, 0);