I have used Spring's AbstractPdfView to generate Pdf Documents. I am trying to add footer to each page on the document but it doesn't seem to work. This is what I have so far..
protected void buildPdfDocument(@SuppressWarnings("rawtypes") Map map, Document doc,
PdfWriter writer, HttpServletRequest req, HttpServletResponse response)
throws Exception {
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "attachment;filename=UserAccessReport.pdf");
doc.setPageSize(PageSize.LEGAL.rotate());
String date = new SimpleDateFormat("MM/dd/yyyy").format(new Date()).toString();
String headerString = "Report Date: "+date;
HeaderFooter hf = new HeaderFooter(new Phrase(headerString), true);
doc.setFooter(hf);
doc.newPage();
PdfPTable table = new PdfPTable(8);
table.setHorizontalAlignment(Element.ALIGN_CENTER);
///add table cells
doc.add(table);
}
Code above doesn't add any footer to the document.
If I add the HeaderFooter element to the document before calling newPage, like...
HeaderFooter hf = new HeaderFooter(new Phrase(headerString), true);
doc.setFooter(hf);
doc.add(hf);
doc.newPage();
in this case I see weird behavior. First page in the document is a blank document and the second page has the table with footer as expected. I understand why two pages are created but don't understand why footer wasn't added to first page.
If I moved add to after calling newPage then again, there is no footer after the table..