IText ignores space added after images

I have a problem formatting a PDF 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 by one, 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 only occurs if the image is the first object of a new page!

Images are screenshots that are scaled to fit 385x500 pixels. Texts and screenshots spread over several pages. I already tried to fill paragraphs, tables and blank images to force space ... nothing has worked so far ...

+4
source share
1 answer

Where is your space going? This is on the previous page!

If the image does not fit on one page, iText saves it for the next page and first adds other content.

How to avoid this? Use writer.setStrictImageSequence(true);

Now iText will not try to add as much content as possible on the current page.

This answer was taken from my book "iText in Action - Second Edition" p52.

+5
source

Source: https://habr.com/ru/post/1437446/


All Articles