This page will provide the tutorial for how to add header and footer in every page of PDF using iText in java. iText provides PdfPageEventHelper class that has different event methods that is called while writing PDF. To add header and footer we need to create a class extending PdfPageEventHelper and override onStartPage and onEndPage methods.
How to add header and footer using event in Java?
Use event class to add header and footer. Using PdfWriter.setPageEvent , we can register our event class. Create a rectangle and set it to PdfWriter using PdfWriter.setBoxSize() method. In the example we are creating two pages. The event will automatically be called to add header and footer. CreateHeaderFooter.java.
How to add header and footer in pdfpageeventhelper?
PdfPageEventHelper class has different event methods for PDF. It implements PdfPageEvent interface. Some event methods of PdfPageEventHelper are as below To add header and footer, we need to override onStartPage and onEndPage methods.
What is iText pdfpageeventhelper?
The com.itextpdf.text.pdf.PdfPageEventHelper contains all the events that occur when iText is writing a PDF document. By extending from this class and overriding these methods, we can write additional data to the PDF document when these events occur. Let’s take a look at the events.
What version of iText do I need to add a header?
You are using iText 5 for .NET. The current version is iText 7 for .NET. The AddHeader has been deprecated a long time ago and has been removed from iTextSharp. Adding headers and footers is now done using page events.
What happened to the addheader in iTextSharp?
The AddHeader has been deprecated a long time ago and has been removed from iTextSharp. Adding headers and footers is now done using page events. The examples are in Java, but you can find the C# port of the examples here and here (scroll to the bottom of the page for links to the .cs files). Make sure you read the documentation.
What is the current version of iText?
The current version is iText 7 for .NET. The AddHeader has been deprecated a long time ago and has been removed from iTextSharp. Adding headers and footers is now done using page events. The examples are in Java, but you can find the C# port of the examples here and here (scroll to the bottom of the page for links to the .cs files).