【问题标题】:iText ignores space added after imagesiText 忽略图像后添加的空间
【发布时间】:2012-10-02 18:21:40
【问题描述】:

我在使用 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 |                            |
-----------                           --

* = 空格

这个问题似乎只有当图像是新页面的第一个对象时才会出现!

图片是经过缩放以适应 385x500 点的屏幕截图。文本和屏幕截图分布在几页上。 我已经尝试填充段落、表格和空白图像以强制空间...到目前为止没有任何效果...

【问题讨论】:

    标签: java image itext space


    【解决方案1】:

    你的空间去哪儿了?在上一页!

    如果图像不适合一页,iText 会将其保留到下一页,然后先添加其他内容。

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

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

    这个答案取自我的书“iText in Action - Second Edition”p52。

    【讨论】:

    • 更新:发现它现在是一个名为:StrictImageSequence的属性
    • writer 是com.itextpdf.text.pdf.PdfWriter 类的一个实例(请注意,最初的问题是关于 iText 的 Java 版本)。
    猜你喜欢
    • 1970-01-01
    • 2021-05-16
    • 1970-01-01
    • 2012-12-11
    • 2017-06-06
    • 1970-01-01
    • 2018-04-08
    • 2016-04-02
    • 2012-05-10
    相关资源
    最近更新 更多