我已经使用Spring的AbstractPdfView生成Pdf文档。我正在尝试将页脚添加到文档的每个页面上,但似乎不起作用。这是我到目前为止..itext文档每页页脚 - Spring MVC
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);
}
上面的代码不会添加任何页脚到文档。
如果我打电话NEWPAGE,像以前一样的HeaderFooter元素添加到文档...
HeaderFooter hf = new HeaderFooter(new Phrase(headerString), true);
doc.setFooter(hf);
doc.add(hf);
doc.newPage();
在这种情况下,我看到怪异的行为
。文档中的第一页是空白文档,第二页有预期的页脚。我理解为什么两个页面被创建为 ,但不明白为什么页脚未被添加到第一页。
如果我感动,然后再调用NewPage公司,在该表后无尾后增加..
Spring不支持新版本的iText开箱。他们仍然坚持在2.7。我只是继续与原来的春天的版本.. Ofcourse有方法来扩展Spring API和使用新的iText库..但我只是想在内置支持.. http://stackoverflow.com/questions/9161956/spring -mvc-abstractpdfview-iText的-JAR版本 – RKodakandla 2012-08-12 01:05:29