Adding Page Footer
import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfPageEventHelper;
import com.lowagie.text.pdf.PdfWriter;
public class PageFooterPDF {
public static void main(String[] args) {
Document document = new Document(PageSize.A4, 50, 50, 70, 70);
try {
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("PageFooterPDF.pdf"));
document.open();
document.add(new Paragraph("text"));
Rectangle page = document.getPageSize();
PdfPTable foot = new PdfPTable(1);
foot.addCell("Page 1");
foot.setTotalWidth(page.width() - document.leftMargin() - document.rightMargin());
foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
writer.getDirectContent());
document.close();
} catch (Exception de) {
de.printStackTrace();
}
}
}
itext.zip( 1,748 k)Related examples in the same category