我想在我的 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。
谢谢