Java Textext Footer

I am trying to create a PDF file using the JSP page and my coding scheme as follows:

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();

The page footer does not apply to PAGE 01 as soon as I directly invoke. document.newPage();
How can I get the footer from the whole document?

+3
source share
1 answer

setFooter (footer) should be called before opening the document

The corrected code as follows

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

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

Source: https://habr.com/ru/post/1769332/


All Articles