Why aren't images added sequentially?
I am working on a pdf report that contains topics and images (charts). The document is formatted this way:
NR. TOPIC TITLE FOR TOPIC 1
CHART IMAGE for topic 1 (from bytearray)
NR. TOPIC TITLE FOR TOPIC 2
CHART IMAGE for topic 2 ...
Let's assume that I add this information in a loop, and that the loop runs 10 times. I expect 10 topic titles all directly followed by the image.
However, if the page end is reached and a new image should be added, I notice that the image is moved to the next page and the next topic title is printed on the previous page.
So on paper we have:
page 1: topic 1
image topic 1
topic 2
image topic 2
topic 3
topic 4
page 2: image topic 3
image topic 4
topic 5
image topic 5
Posted on StackOverflow on Mar 26, 2014 by wim boone
If you have a PdfWriter instance (for instance writer), you need to force iText to use strict image sequence like this:
writer.setStrictImageSequence(true);
Otherwise, iText will postpone adding images until there's sufficient space on the page to add the image.