【发布时间】:2015-10-05 09:56:21
【问题描述】:
我对 itext 库有一个问题,可以描述如下:
我想通过使用第二个段落的 spacingBefore 属性在两个段落之间放置一个垂直间距。
问题在于,从某个空间单位值(默认为点单位)开始,itext 会导致第二个段落显示在新页面上,即使显然有足够的空间将两个段落放在同一页面上。
这段代码说明了这种情况:
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();
}
有人解释过这种奇怪的行为吗?
提前致谢
【问题讨论】: