【问题标题】:iText page wrapping- changes order of elementsiText 页面换行 - 更改元素的顺序
【发布时间】:2023-04-09 23:17:01
【问题描述】:

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

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

图像的高度使得 PDF 页面可以容纳 3 个图像,但如果页面上有文本,则只能容纳 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 设置任何奇怪的包装参数,这个例子真的只是一个简单的例子。

关于为什么它似乎错误地自动包装的任何想法?

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

非常感谢。

【问题讨论】:

    标签: java pdf itext word-wrap


    【解决方案1】:

    自己想办法;)

    writer.setStrictImageSequence(true); 
    

    iText 的设计决定不将图像一分为二,而是先添加其他内容。

    设置此布尔值会导致 iText 尊重排序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-05
      相关资源
      最近更新 更多