我想在我的pdf文档中添加一个页脚但是代码不能正常工作,请不要将此问题视为重复...此代码在类似问题的答案中是相同的;
protected void buildPdfDocument(Map model, Document document,
PdfWriter writer, HttpServletRequest request,
HttpServletResponse response) throws Exception {
response.setCharacterEncoding("application/pdf;charset=UTF-8");
document.setPageSize(PageSize.A4.rotate());
Image imf= Image.getInstance("D:\\footer.png");
imf.setAlignment(Image.MIDDLE);
imf.scaleAbsoluteHeight(20);
imf.scaleAbsoluteWidth(20);
imf.scalePercent(100);
Chunk chunk = new Chunk(imf, 0, -45);
HeaderFooter footer = new HeaderFooter(new Phrase(chunk), false);
footer.setAlignment(Element.ALIGN_CENTER);
footer.setBorder(Rectangle.NO_BORDER);
document.setFooter(footer);
document.open();
document.newPage();
// add tables and other elements
document.close();
}
然后执行代码后,图像没有显示..我正在使用iText v2.1.7。
谢谢
答案 0 :(得分:1)
尝试在document.newPage();