Java iText 添加新页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4284691/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 15:22:55  来源:igfitidea点击:

iText add new page

javartfitext

提问by Thizzer

How can you add a new page to an iText document? document.newPage();doesn't seem to work.

如何将新页面添加到 iText 文档?document.newPage();似乎不起作用。

I am using iText with RTF support from http://sourceforge.net/projects/itextrtf/

我正在使用来自http://sourceforge.net/projects/itextrtf/ 的带有 RTF 支持的 iText

Part of my code:

我的部分代码:

Font titleFont = new Font(Font.COURIER, 14, Font.BOLD);
document.add(new Paragraph("Title1", titleFont));

Table table = new Table(4);
table.setBorderWidth(0);

// Filling table

document.add(table);

document.newPage();

document.add(new Paragraph("Title2", titleFont));

Table table = new Table(4);
table.setBorderWidth(0);

// Filling table

document.add(table);

采纳答案by Thizzer

The problem was I was using a wrong RTF reader, the breakline was there, the reader just didn't render it.

问题是我使用了错误的 RTF 阅读器,断裂线在那里,阅读器只是没有呈现它。

回答by T.J. Crowder

Edit: Re your updated question with code, neither of the below seems to apply. Leaving in case they help someone else out.

编辑:用代码重新回答你更新的问题,以下两个似乎都不适用。离开以防万一他们帮助别人。

Calling newPagetells iText to place subsequent objects on a new page. The new page will only actually get created when you place the next object (at least, that's what it does for me). Also, newPageonly creates a new page if the current page is not blank; otherwise, it's ignored; you can use setPageBlank(false)to overcome that.

调用newPage告诉 iText 将后续对象放置在新页面上。只有在放置下一个对象时才会真正创建新页面(至少,这对我来说是这样)。此外,newPage仅当当前页面不为空白时才创建新页面;否则,它被忽略;你可以setPageBlank(false)用来克服它。

回答by Mark Storer

RTF is no longer supported by iText, as the main author of the relevant code moved on to other projects... or was transformed into a frog... or something. Anyway, I recommend you seek a new RTF library, or perhaps start maintaining it yourself?

iText 不再支持 RTF,因为相关代码的主要作者转移到其他项目......或者变成了青蛙......或其他东西。无论如何,我建议您寻找一个新的 RTF 库,或者自己开始维护它?

At any rate, the Source Is Available, and I suspect the RTFDocument/RTFWriter ignores newPage(). Nope. RtfWriter2.java:

无论如何,源是可用的,我怀疑 RTFDocument/RTFWriter 忽略了 newPage()。不。RtfWriter2.java:

/**
 * Adds a page break
 *
 * @return <code>false</code>
 */
public boolean newPage() {
    rtfDoc.add(new RtfNewPage(rtfDoc));
    return true;
}

which should just write "//page" into the output file. Is it there?

应该只将“//page”写入输出文件。它在吗?