iText - 将内容添加到现有页面的底部 [英] iText - add content to the bottom of an existing page

查看:1454
本文介绍了iText - 将内容添加到现有页面的底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在PDF文件的每个页面添加一段文字。 这个答案在SO 中运行正常。但是,文本被添加到页面顶部。我想将我的文字添加到每个页面的底部。我该怎么办?

I want to add a piece of text to every page of a PDF file. This answer in SO works fine. But, the text is added to the top of the page. I would like to add my text to the bottom of each page. How do I do this?

以下是代码的相关部分。

Here is the relevant part of the code.

    while (iteratorPDFReader.hasNext()) {
        PdfReader pdfReader = iteratorPDFReader.next();

        // Create a new page in the target for each source page.
        while (pageOfCurrentReaderPDF < pdfReader.getNumberOfPages()) {
            document.newPage();
            pageOfCurrentReaderPDF++;
            currentPageNumber++;
            page = writer.getImportedPage(pdfReader, pageOfCurrentReaderPDF);
            cb.addTemplate(page, 0, 0);

            document.add(new Paragraph("My Text here"));  //As per the SO answer

        }
        pageOfCurrentReaderPDF = 0;
    }

代码是接受文件夹,读取PDF文件的函数的一部分在其中并将它们合并为一个文件。所以,我想在上面的循环中添加文本,而不是再次迭代文件。

The code is part of a function which accepts a folder, reads the PDF files in it and merges them into one single file. So, I would like to add the text in the above loop itself, instead of iterating the file once again.

推荐答案

看看第6章:连接和拆分PDF文档。

Have a look at chapter 6 of iText in Action, 2nd edition, especially at subsection 6.4.1: Concatenating and splitting PDF documents.

清单6.22 , ConcatenateStamp.java ,向您展示如何从页面副本创建PDF (在您的情况下:所有页面)多个其他PDF;该示例另外添加了一个新的Page X of Y页脚;这演示了如何在合并源文件的同时在页面上的给定位置添加内容。

Listing 6.22, ConcatenateStamp.java, shows you how you should create a PDF from copies of pages (in your case: all pages) of multiple other PDFs; the sample additionally adds a new "Page X of Y" footer; this demonstrates how you can add content at given positions on the pages while merging the source files.

这篇关于iText - 将内容添加到现有页面的底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆