I do have a problem formatting a PDF document with iText for java (Version 5.3.2).
My document should look like this:
text1word1 text1word2 text1word3. --
*** |
----------- |
| image 1 | |
----------- |- page 1
*** |
*** |
text2word1 text2word2 text2word3. |
*** --
----------- --
| image 2 | |
----------- |
*** |
*** |- page 2
text3word1 text3word2 text3word3. |
*** |
----------- |
| image 3 | |
----------- --
* = space
But after adding all the elements one after each other, i get something like this:
text1word1 text1word2 text1word3. --
*** |
----------- |
| image 1 | |
----------- |- page 1
*** |
*** |
text2word1 text2word2 text2word3. |
*** --
----------- --
| image 2 | (where is all my space here gone??)
----------- <----/ |
text3word1 text3word2 text3word3. |- page 2
*** |
----------- |
| image 3 | |
----------- --
* = space
The problem seems to occure only if the image is the first object of a new page!
The images are screenshots which are scaled to fit into 385×500 points. The texts and the screenshots spread over several pages.
I already tried to fill in paragraphs, tables and blank images to force the space… nothing did work so far…
Where is your space gone? It’s on the previous page!
If an image doesn’t fit on one page, iText keeps it for the next page, and adds the other content first.
How to avoid this? Use
writer.setStrictImageSequence(true);Now iText won’t try to add as much content on the current page as possible.
This answer was taken from my book “iText in Action – Second Edition” p52.