Sunday, May 25, 2014

Adding Footer and Header into PDF with iText

iText version - 2.1.7

Header/Footer only
Document document = new Document();
HeaderFooter header = new HeaderFooter(new Phrase("This is header"), false);
HeaderFooter footer = new HeaderFooter(new Phrase("This is footer"), false);
document.setHeader(header);
document.setFooter(footer);


Header/Footer with page number
Document document = new Document();
HeaderFooter header = new HeaderFooter(new Phrase("This is header"), true);
HeaderFooter footer = new HeaderFooter(new Phrase("This is footer"), true);
document.setHeader(header);
document.setFooter(footer);


Header/Footer with font
Document document = new Document();
Font font = new Font(Font.TIMES_ROMAN, 11);  // font family, font size
HeaderFooter header = new HeaderFooter(new Phrase("This is header", font), true);
HeaderFooter footer =new HeaderFooter(new Phrase("This is footer", font), false);
document.setHeader(header);
document.setFooter(footer);


Done!!

LinkWithin

Related Posts Plugin for WordPress, Blogger...