Itext - 如何克隆带有 acrofields 的页面?
我正在用 Java 编写一个程序来打印宾果卡的 PDF 文件。每页都是一张卡片。为了方便起见,我创建了一个带有 acrofields 的模板 PDF 文件,这样程序只需要创建该模板的副本,用数字填充 acrofields,然后将其展平。截至目前,我可以创建 1 张宾果卡。我想在一个 PDF 文件中包含多个页面(即多张卡片)。但我不知道该怎么做。我读到的是 PDFStamper 与唯一一个 PDFReader 对象关联。有没有一种方法可以做到这一点,而无需创建多个 PDF 文件并将它们合并为一个(我上次这样做了,我发现非常慢)提前致谢!
I'm writing a program in Java that prints PDF files of Bingo Cards. Each page is one card. To make it easy for me, I created a template PDF file with acrofields, so that the program will only need to create a copy of this template, fill the acrofields with numbers, then flatten it. As of now, I can create 1 bingo card. I want to have multiple pages (thus, multiple cards) in one PDF file. But I do not have an idea how to do this. What I read is that a PDFStamper is associated to a one and only one PDFReader object. Is there a way I can do this without resorting to creation of multiple PDF files and combining them into one (I did this last time and I found really slow) Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我花了一段时间才弄清楚这一点。这不是最有效的编码方式,但本质上它的作用如下:
这是我的实现,您可以尝试修改以满足您的需求:
copyPdf()
方法创建临时文件,用于允许填写表单而不影响整个文档。如果您找到更有效的方法来做到这一点,请告诉我。另外,我发现在基于 Intel 的 Mac 与 Windows 计算机上,Mac 完成此操作的速度要快得多。
如果您不反对购买 iText 参考书,我会推荐 Bruno Lowagie 的“iText in Action,第二版”。这是一本很棒的书,而且非常有帮助。
Took me a while to figure this out. It's not the most efficient way to code, but here's essentially what it does:
Here's my implementation that you can try and modify to fit your needs:
The
copyPdf()
method creates temporary files that are used to allow form filling without affecting the entire document. If you find a more efficient way to do this, let me know.Also, I've found that on Intel Based Mac vs Windows Computer, the Mac completes this much faster.
If you're not opposed to getting a reference book for iText, I would recommend "iText in Action, Second Edition" by Bruno Lowagie. It is a great book and very helpful.
因此,这是不使用 Zach 的“copyPdf”方法的代码,正如 Mark Storer 和 MaxArt 所建议的:
So, here's the code without using Zach's "copyPdf" method, as Mark Storer and MaxArt suggested: