Java iText页脚

时间:2010-10-13 12:01:00

标签: java itext

我正在尝试使用JSP页面和我的编码大纲生成PDF,如下所示,

Document document           = new Document(PageSize.A4,70/*Left*/,70/*Right*/,140/*Top*/,30/*Bottom*/);

response.setContentType("application/pdf" );
response.setHeader("Content-Disposition","inline; filename=vishwa-mandate.pdf");

PdfWriter.getInstance(document, response.getOutputStream());
document.open();

HeaderFooter footer = new HeaderFooter(new Phrase("This is page "), true);
document.setFooter(footer);

/* PAGE 01 */

document.newPage(); 

/* PAGE 02 + */

document.close();

我明确致电document.newPage();后,页脚不适用于第01页 如何在整个文档中获取页脚?

1 个答案:

答案 0 :(得分:6)

在打开文档之前应该调用

setFooter(页脚)

更正后的代码如下

HeaderFooter footer = new HeaderFooter(new Phrase("This is page "), true);
document.setFooter(footer);

// Document should open after setting the footer
document.open();