iText 页面换行 - 更改元素的顺序

发布于 2024-07-13 07:42:44 字数 890 浏览 3 评论 0原文

当我遇到这个问题时,我正在使用 iText 生成 PDF 报告,并编写了一个简单的示例来说明它。

我正在组合简单的段落和图像。

图像的高度使得 3 个图像适合 PDF 页面,但如果页面上有文本,则仅适合 2 个图像。

我使用以下代码创建 PDF:

    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();

我希望输出看起来像这样

hello world1
image
image
<page break>
image
hello world2

相反,我得到的是,

Hello world 1
image
image
hello world 2
<page break>
image

我没有使用 iText 设置任何奇怪的换行参数,该示例实际上只是一个简单的示例。

关于为什么它似乎会错误地自动换行有什么想法吗?

在实际情况下,仅仅添加分页符并不是一个可接受的解决方案。

非常感谢。

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.

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.

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

Instead, what I get is,

Hello world 1
image
image
hello world 2
<page break>
image

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.

Thanks very much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃兔兔 2024-07-20 07:42:45

我自己弄清楚了;)

writer.setStrictImageSequence(true); 

iText 中的一个设计决定是不将图像切成两半,而是首先添加其他内容。

设置此布尔值会导致 iText 遵守顺序。

Figure it out myself ;)

writer.setStrictImageSequence(true); 

It was a design decision in iText to not cut images in two, instead it adds other content first.

setting this boolean causes iText to respect the ordering.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文