将表格继续到下一个 PDF 页,并打印中间的文本

发布于 2024-12-27 01:29:52 字数 291 浏览 2 评论 0原文

我不知道我想做的事情是否可能,而且对于一些非常微不足道的事情来说,这可能是太多的工作。我有一个创建 PDF 的 servlet。我正在使用 iText 写入创建的 pdf,在我的 pdf 中,我有一个可以更改文档大小的动态表。每当需要转到下一页时,我想在文档底部打印“下一页继续”。问题是我永远不会知道文档中分页符发生在哪里。

如果可能的话,我非常乐意为此添加代码。另外,如果不清楚,请随时提问,谢谢。

编辑:可能是在自言自语,但我认为这是可能的唯一方法是如果有一种方法可以意识到刚刚创建了一个新页面。

I dont know if what I am trying to do is even possible, and it might be too much work for something very insignificant. I have a servlet that creates a PDF. I am using iText to write to the created pdf, in my pdf I have a dynamic table that can change the size of the document. I would like to print "Continued on next page" at the bottom of the document whenever it needs to go to the next page. The problem is I will never know where the page break occurs in my document.

I am more than happy to add code to this, if this is possible. Also, if this isnt clear, feel free to ask questions, thanks.

EDIT: Probably talking to myself, but The only way that I think this is possible is if there is a method that realizes that a new page has just been created.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

怼怹恏 2025-01-03 01:29:52

您可以尝试在 pdf 生成器类中应用此代码段

private static final float FOOTER_MARGIN = 15;
private static final float PAGE_MARGIN_LEFT = 36;
private static final float PAGE_MARGIN_RIGHT = 36;
private static final float PAGE_MARGIN_BOTTOM = 36 + FOOTER_MARGIN;
private static final float PAGE_MARGIN_TOP = 36;
private static final Rectangle PAGE_SIZE = PageSize.A4;

//Put this in your generator method
//..
Document document = new Document(PAGE_SIZE, 
         PAGE_MARGIN_LEFT, PAGE_MARGIN_RIGHT, PAGE_MARGIN_BOTTOM, MARGIN_TOP); 
PdfWriter writer = PdfWriter.getInstance(document, OUTPUT_STREAM); 
writer.setPageEvent(new HeaderFooter()); 
//..

private class HeaderFooter extends PdfPageEventHelper {

    @Override
    public void onEndPage(PdfWriter writer, Document document) {
        Phrase footerText = new Phrase("Continued On Next Page");
        ColumnText.showTextAligned(
                writer.getDirectContent(),
                Element.ALIGN_LEFT, footerText,
                PAGE_MARGIN_LEFT, PAGE_MARGIN_BOTTOM - FOOTER_MARGIN, 0);
    }
}

仅供参考,有一堆 iText 示例,在您的情况下搜索页脚。希望这有帮助。

You can try to apply this snippet in your pdf generator class:

private static final float FOOTER_MARGIN = 15;
private static final float PAGE_MARGIN_LEFT = 36;
private static final float PAGE_MARGIN_RIGHT = 36;
private static final float PAGE_MARGIN_BOTTOM = 36 + FOOTER_MARGIN;
private static final float PAGE_MARGIN_TOP = 36;
private static final Rectangle PAGE_SIZE = PageSize.A4;

//Put this in your generator method
//..
Document document = new Document(PAGE_SIZE, 
         PAGE_MARGIN_LEFT, PAGE_MARGIN_RIGHT, PAGE_MARGIN_BOTTOM, MARGIN_TOP); 
PdfWriter writer = PdfWriter.getInstance(document, OUTPUT_STREAM); 
writer.setPageEvent(new HeaderFooter()); 
//..

private class HeaderFooter extends PdfPageEventHelper {

    @Override
    public void onEndPage(PdfWriter writer, Document document) {
        Phrase footerText = new Phrase("Continued On Next Page");
        ColumnText.showTextAligned(
                writer.getDirectContent(),
                Element.ALIGN_LEFT, footerText,
                PAGE_MARGIN_LEFT, PAGE_MARGIN_BOTTOM - FOOTER_MARGIN, 0);
    }
}

FYI, there are bunch of iText examples, in your case search for footer. Hope this helps.

冬天旳寂寞 2025-01-03 01:29:52

您也许可以使用 setSkipLastFooter(boolean)。这样,它将打印表格的页脚行,该行在除最后一页之外的每一页上都有连续的文本。您需要确保在表格上设置FooterRows。

您还可以使用 PdfPageEventHelper,它允许您拦截各种页面事件,包括结束页面事件。在 onEndPage 方法内,您可以将“下一页继续”文本添加到文档中。

You can probably make use of setSkipLastFooter(boolean). This way, it will print the footer row of your table that has the continued text on every page except the last. You will need to be sure to setFooterRows on the table.

You could also use PdfPageEventHelper, which allows you to intercept various page events including end page event. Inside the onEndPage method you can add the "Continued On Next Page" text to the document.

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