iText页面包装 - 改变元素的顺序 [英] iText page wrapping- changes order of elements
问题描述
当我遇到这个问题时,我正在使用iText生成PDF报告,并编写了一个简单的例子来说明它。
I'm using iText to generate PDF reports when I came across this issue, and worked up a simple example to illustrate it.
我正在组合简单的段落和图像。
I'm combining simple paragraphs, and images.
图像的高度使得3适合PDF页面,但是当文本在页面上时,只有2张图像适合。
The height of the images is such that 3 will fit on a PDF page, but when if text is on a page, only 2 images will fit.
我使用以下代码创建PDF:
I create my PDF with the following code:
Document document = new Document(PageSize.LETTER, 0, 0, 0, 0);
PdfWriter writer = PdfWriter.getInstance(document, fileOutput);
document.open();
document.add(new Paragraph("hello world1"));
addImage(document);
addImage(document);
addImage(document);
document.add(new Paragraph("hello world2"));
document.close();
我希望输出看起来像这样
I expect the output to look like this
hello world1
image
image
<page break>
image
hello world2
相反,我得到的是,
Hello world 1
image
image
hello world 2
<page break>
image
我没有使用iText设置任何奇怪的包装参数,例子真的只是一个简单的。
I'm not setting any sort of odd wrapping parameters using iText, the example really is just a simple one.
关于为什么它似乎不正确地自动换行的任何想法?
Any ideas on why it seems to be auto-wrapping this incorrectly?
在实际情况中,仅添加分页符是不可接受的解决方案。
In the real case, just adding a page break is not an acceptable solution.
非常感谢。
推荐答案
自己搞清楚;)
writer.setStrictImageSequence(true);
iText中的设计决定是不将图像切成两半,而是首先添加其他内容。
It was a design decision in iText to not cut images in two, instead it adds other content first.
设置此布尔值会使iText遵守排序。
setting this boolean causes iText to respect the ordering.
这篇关于iText页面包装 - 改变元素的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!