Java iText忽略图像后添加的空格

Java iText忽略图像后添加的空格,java,image,itext,space,Java,Image,Itext,Space,我确实在使用iText for java(版本5.3.2)格式化PDF文档时遇到问题 我的文档应如下所示: text1word1 text1word2 text1word3. -- *** | ----------- | | image 1 | | -----------

我确实在使用iText for java(版本5.3.2)格式化PDF文档时遇到问题

我的文档应如下所示:

text1word1 text1word2 text1word3.    --
***                                   |
-----------                           |
| image 1 |                           |
-----------                           |- page 1
***                                   |
***                                   | 
text2word1 text2word2 text2word3.     |
***                                  --
-----------                          --
| image 2 |                           |
-----------                           |
***                                   |
***                                   |- page 2
text3word1 text3word2 text3word3.     | 
***                                   |
-----------                           |
| image 3 |                           |
-----------                          --
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 |                            |
-----------                           --
*=空间

但在一个接一个地添加所有元素后,我得到如下结果:

text1word1 text1word2 text1word3.    --
***                                   |
-----------                           |
| image 1 |                           |
-----------                           |- page 1
***                                   |
***                                   | 
text2word1 text2word2 text2word3.     |
***                                  --
-----------                          --
| image 2 |                           |
-----------                           |
***                                   |
***                                   |- page 2
text3word1 text3word2 text3word3.     | 
***                                   |
-----------                           |
| image 3 |                           |
-----------                          --
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 |                            |
-----------                           --
text1word1 text1word2 text1word3--
***                                    |
-----------                            |
|图1 ||
-----------|-第1页
***                                    |
***                                    |
text2word1 text2word2 text2word3|
***                                   --
-----------                           --
|图2 |(我的空间都到哪里去了??)

-----------你的空间到哪里去了?在上一页

如果一个图像不适合一个页面,iText会将其保留到下一个页面,并首先添加其他内容

如何避免这种情况?使用
writer.setStritimagesequence(true)

现在iText不会尝试在当前页面上添加尽可能多的内容


这个答案取自我的书《iText在运行-第二版》第52页。

更新:发现它现在是一个名为:StrictImageSequence
writer
的属性,是
com.itextpdf.text.pdf.PdfWriter
类的一个实例(请注意,原始问题是关于iText的Java版本)。