itext spacingBefore应用于Paragraph的属性会导致新页面 [英] itext spacingBefore property applied to Paragraph causes new page

查看:1519
本文介绍了itext spacingBefore应用于Paragraph的属性会导致新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对itext库有一个问题,可以描述如下:

I have an issue with the itext library that can be described as follow :

我想通过使用 spacingBefore在两个段落之间放置一个垂直空格第二段的属性。

I want to put a vertical space between two paragraphs by using the spacingBefore property on the second paragraph.

问题是从空间单位的某个值(默认点单位),itext导致第二段显示在新页面上,即使有明显的足够的空间将2段落在同一页面上。

The problem is that from a certain value of space units (by default point unit), itext causes the second paragraph to be displayed on a new page even though there is obviously enough space to put the 2 paragraphs on the same page.

此代码说明了这种情况:

This code illustrates this situation :

    public static void main(String[] args) throws Exception {
       Document document = new Document();
       OutputStream result = new FileOutputStream("output.pdf");
       PdfWriter.getInstance(document, result);
       document.open();

       Paragraph paragraph1 = new Paragraph("First paragraph");

       Paragraph paragraph2 = new Paragraph("Second paragraph");
       //380 causes the new page...
       paragraph2.setSpacingBefore(380f);

       //...whereas 370 does not
       //  paragraph2.setSpacingBefore(370f);

       document.add(paragraph1);
       document.add(paragraph2);

       document.close();
}

是否有人解释这种奇怪的行为?

Does someone hava an explication of this strange behaviour?

提前致谢

推荐答案

如布鲁诺所说,我是使用2012年发布的旧错误版本的itext:5.1.2。此错误由版本5.5.1修复,如更改日志中所述 http://itextpdf.com/changelog/551

As stated by Bruno, I was using an "old" buggy version of itext : 5.1.2 released in 2012. This bug was fixed by version 5.5.1 as mentionned in the changelog http://itextpdf.com/changelog/551 :


关于a之前和之后的间距的错误修正新页面已创建。

Bugfix regarding spacing before and after when a new page is created.

使用较新版本时,everthing效果很好:)

When using a newer version, everthing works just fine :)

这篇关于itext spacingBefore应用于Paragraph的属性会导致新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆