iText 添加新页面

发布于 2024-10-04 08:38:01 字数 602 浏览 0 评论 0原文

如何向 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

长伴 2024-10-11 08:38:01

编辑:用代码重新更新您的问题,以下内容似乎都不适用。离开,以防他们帮助别人。

调用 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 use setPageBlank(false) to overcome that.

污味仙女 2024-10-11 08:38:01

iText 不再支持 RTF,因为相关代码的主要作者转移到了其他项目...或者变成了青蛙...或者其他什么。不管怎样,我建议你寻找一个新的 RTF 库,或者也许开始自己维护它?

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

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

应该只将“//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:

/**
 * 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?

奈何桥上唱咆哮 2024-10-11 08:38:01

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文