I am using iTextSharp to generate PDF documents, but the content of my page is overlapping with my page footer. I want the content that overlaps to move to the next page. Right now i m using
document.newpage(), but I want the new page to be created automatically instead.
I create header/footer through this class:
public class ITextEvents : PdfPageEventHelper and I used this function:
public override void OnEndPage.
This is the result that I'm getting:
I want the last box to move to the next page automatically.
Look at the TextFooter example to learn how to add events in iText 7. You should override the
handleEvent() method in
IEventHandler interface and assign this event to the
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest)); Document document = new Document(pdfDoc); pdfDoc.addEventHandler(PdfDocumentEvent.END_PAGE, new TextFooterEventHandler(document));
Assuming that you are adding the flowing content using
document.add(), you have to make sure that you define a bottom margin that is sufficiently large to accommodate the footer.
You don't share your code, but suppose that you have something like:
canvas.moveTo(36, 50); canvas.lineTo(559, 50); canvas.strike();
This draws a line from
x = 36 to
x = 559 at
y = 50.
Suppose you have created your
Document like this:
Document document = new Document(pdfDoc);
In this case, you are creating a document with pages in the A4 format (595 x 842 user units) and margins of 36 user units. As the bottom margin is only 36 user units, your content risks overlapping with the line drawn at 50 user units from the bottom.
You should add one more line where you create the
document.setMargins(36, 36, 55, 36);
Now you have a bottom margin of 55 user units and the line you draw at 50 user units no longer overlaps.
Note: I use the term user units because that's how we define measurements in PDF. By default 1 user unit equals 1 point. The default margin is 36 user units or half an inch.
Click Why is my content overlapping with my footer? if you want to see how to answer this question in iText 5.