/** The headertable. */
PdfPTable table = new PdfPTable(2);
/** A template that will hold the total number of pages. */
PdfTemplate tpl = writer.getDirectContent().createTemplate(100, 100);
/** The font that will be used. */
BaseFont helv = null;
try
{
helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false);
}
catch (DocumentException e)
{
}
catch (IOException e)
{
}
PdfContentByte cb = writer.getDirectContent();
// cb.saveState();
// write the headertable
table.setTotalWidth(document.right() - document.left());
table.writeSelectedRows(0, -1, document.left(), document.getPageSize().getHeight() - 50, cb);
// compose the footer
String text = "Page " + writer.getPageNumber();
float textSize = helv.getWidthPoint(text, 12);
float textBase = document.bottom() - 20;
cb.beginText();
cb.setFontAndSize(helv, 12);
float adjust = helv.getWidthPoint("0", 12);
cb.setTextMatrix(document.right() - textSize - adjust, textBase);
cb.showText(text);
cb.endText();
cb.addTemplate(tpl, document.right() - adjust, textBase);
// cb.saveState();