How to add header and footer in iText 7?

If you are new to iText, you should use iText 7 and use event handlers to add headers and footers. See chapter 3 of the iText 7 Jump-Start Tutorial for .NET.

Where to find iText events in PDF file?

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.

How to add header and footer in PDF in Java?

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.

Is it possible to create a PDF document in iText?

Upon execution, the above program creates a PDF document, displaying the following message. If you verify the specified path, you can find the created PDF document as shown below. Since this is an empty document, if you try to open this document, it will display an error message, as shown in the following screenshot.

How to create an empty PDF document in iText?

While instantiating this class, you need to pass a PdfDocument object as a parameter to its constructor. Following are the steps to create an empty PDF document. The PdfWriter class represents the Doc Writer for a PDF. This class belongs to the package com.itextpdf.kernel.pdf.

What does the pdfwriter class do in iText?

The PdfWriter class represents the Doc Writer for a PDF. This class belongs to the package com.itextpdf.kernel.pdf. The constructor of this class accepts a string, representing the path of the file where the PDF is to be created.