iText PDF 填写表格并在必要时滚动到第二页
我已经用 Java 成功创建了一个 iText 表单填充应用程序,但遇到了问题,因为动态内容并不总是相同的长度。
基本上,我正在创建发票表格,当然,发票的长度取决于订购的商品数量。
该表格允许 12 个条目,但我不知道如果条目超过 12 个该怎么办。我尝试过添加具有相同模板的页面,但它只是在末尾添加了一个空白页面,然后抛出异常,因为它无法处理传递的附加信息。
知道如何添加多个页面吗?我正在使用 PdfReader 读取输入文件(使用 Acrobat 创建的 .pdf 表单)。然后我使用迭代器逐步遍历字段和压模。
我正在 for 循环中尝试此操作,该循环应该单步执行每个页面,但是当到达第 2 页时,它会出错,因为该文件的 PdfReader 已经存在。将 PdfReader 的创建移到 for 循环之外也没有帮助。
任何意见将不胜感激。
I have successfully created an iText form filling app with Java, but am running into a problem, because the dynamic content is not always the same length.
Basically, I am creating an invoice form, and of course, the length of the invoice depends on how many items were ordered.
The form allows for 12 entries, but I cannot figure out what to do if there is more than 12 entries. I have tried adding a page with the same template, but it just adds a blank page at the end and then throws an exception, because it cannot handle the additional information passed.
Any idea how to add more than one page? I am using PdfReader to read in the input file (a .pdf form created with Acrobat). Then I am using the iterator to step through the fields and the Stamper.
I am trying this inside a for loop that is supposed to step through each page, but when it gets to page 2, it errors out, because the PdfReader for that file already exists. Moving the creation of the PdfReader outside the for loop did not help either.
Any input would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嘿,你使用 pdf AcroForm,否则你无法用 iText 填充它,但 AcroForms 是静态表单,你想要使用的是 XFAForms 一个注入 XML 的 pdf 表单,但 iText 还不完全支持 XFAForms。
您可能会做的是使用第一行产品的坐标并在其上放置一个可以跨多个页面的 PdfPTable,您可以指定在转到另一页时是否需要完成一行,这可以在Bruno Lowagie 撰写的《iText in Action》书中的第 4 章
Hey well you use pdf AcroForm otherwise you couldn't fill it with iText but AcroForms are static forms, what you want to use are XFAForms a pdf form which is injected with XML, but iText doesn't support XFAForms fully yet.
What you might do is use the coordinates of your first line of products and put a PdfPTable on it which can go over multiple pages, you can specify if a row needs to be complete or not when going to another page, this can be read on chapter 4 in the iText in Action book written by Bruno Lowagie