ITextSharp page break creates an unwanted empty page
c#, itext
Solution
This can be caused by three things:
- You're using a very old version of iTextSharp. If so, please upgrade to a more recent version of iTextSharp. We don't fix obsolete versions.
- You're using page events and contrary to what is advised in the documentation, you're adding content in the `onStartPage()` method.
- You're using `writer.setPageEmpty(false);` which is kind of asking iText to consider an empty page as not being empty.
In all other cases, the newPage() method is ignored if you're currently on a page that doesn't have any content.
Problem
Background I've a document that I build up throu various steps. In one of these steps I add content to a Document from a chapter structure I've built containing the content. This part in particular is very simple. It simply adds the content to the document. Sometimes my structure specifies there should be a page break, and thus document.NewPage(); gets executed. This works, usually. We are using ITextSharp version 5.3.2.0. ( A few month old or so) The problem When document.NewPage() get's executed and is very close to the end of the document or perhaps just entered a new page I am guessing, I get an empty page with the rest of my content being added on the following page. Only having the Document to work with at this point I can not seem to find a way how to determine if document.NewPage() should be skipped or not to work around this bug or issue. Thanks