iText 添加新页面
如何向 iText 文档添加新页面? document.newPage();
似乎不起作用。
我正在使用支持 RTF 的 iText http://sourceforge.net/projects/itextrtf/
我的代码的一部分:
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);
How can you add a new page to an iText document? document.newPage();
doesn't seem to work.
I am using iText with RTF support from http://sourceforge.net/projects/itextrtf/
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
编辑:用代码重新更新您的问题,以下内容似乎都不适用。离开,以防他们帮助别人。
调用
newPage
告诉 iText 将后续对象放置在新页面上。只有当您放置下一个对象时,新页面才会真正创建(至少,这对我来说是这样做的)。此外,如果当前页面不为空白,newPage
仅创建一个新页面;否则,它会被忽略;您可以使用setPageBlank(false)
来克服这个问题。
Edit: Re your updated question with code, neither of the below seems to apply. Leaving in case they help someone else out.
Calling
newPage
tells 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,newPage
only creates a new page if the current page is not blank; otherwise, it's ignored; you can usesetPageBlank(false)
to overcome that.iText 不再支持 RTF,因为相关代码的主要作者转移到了其他项目...或者变成了青蛙...或者其他什么。不管怎样,我建议你寻找一个新的 RTF 库,或者也许开始自己维护它?
无论如何,源是可用的,我怀疑 RTFDocument/RTFWriter 忽略了 newPage()。没有。 RtfWriter2.java:
应该只将“//page”写入输出文件。在那里吗?
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?
At any rate, the Source Is Available, and I suspect the RTFDocument/RTFWriter ignores newPage(). Nope. RtfWriter2.java:
which should just write "//page" into the output file. Is it there?
问题是我使用了错误的 RTF 阅读器,断线就在那里,阅读器只是没有渲染它。
The problem was I was using a wrong RTF reader, the breakline was there, the reader just didn't render it.