Reputation:
I am generating a pdf using itext. So when the content of a page exceeds it creates a new page automatically. I am trying to know if it created a new page. If yes I want to add some image on top of the page.
List paylist =new List(List.ORDERED, List.ALPHABETICAL);
paylist.setIndentationLeft(10);
paylist.add(new ListItem("Some text", yourfont));
document.add(paylist);
The content of the list will be dynamic. So I am unable to find whether its a new page it is in the same page. Suggestion please..
Upvotes: 2
Views: 9922
Reputation: 55427
Subclass PdfPageEventHelper
and bind an instance of it to your PdfWriter
:
writer.setPageEvent(new YourCustomPageEventHelper());
Within that class there's a method called onStartPage
that will be called for every page in your document. Use this to add an image to every page, then you don't have to worry about keeping tracking of things. See this page for a bunch of samples.
Upvotes: 3
Reputation: 7512
Check the page number before and after you add content to the document. If the value is different, then a new page has been created.
The page number is returned by the PdfWriter.getPageNumber() method.
Upvotes: 0