在java中使用itext填写pdf表单有问题
我正在使用 iText 填写 pdf 表单,控制台中没有错误,但是当我打开输出 pdf 时,它给出“预期一个 dict 对象”,并在给出另一条消息后显示“此文档在 Adobe reader 中启用了扩展功能。该文档自创建以来已发生更改,并且不再可以使用扩展功能。”
此外,输出 pdf 也有我所做的更改,但它不具有原始 pdf 文档的功能,如上面的消息所示。
我使用了下面的代码...
PdfReader reader = new PdfReader("C:\\Users\\asfs\\Downloads\\1013-Form22.pdf");
String name = "C:\\Users\\asfs\\Downloads\\Temp.pdf";
PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(name));
AcroFields form = stamp.getAcroFields();
String last = "Form22_Dtls[0].Page1[0].Country_C[0]";
form.setField(last, "Sample Country name");
HashMap map = new HashMap();
map = form.getFields();
Iterator iterator = map.keySet().iterator();
while(iterator.hasNext())
System.out.println("Field is >>>"+iterator.next());
// close pdf stamper
stamp.setFormFlattening(true);
stamp.close();
请帮助我。
谢谢
I am using iText to fill pdf form, no error in console, but when i am opening the output pdf it is giving "Expected a dict object" and after it gives another message saying "This document enabled extended features in Adobe reader. The document has been changed since it was created and use of extended features is no longer available."
Also the output pdf have the changes i made but it does not have features of original pdf document, as the above message shows.
I have used below code...
PdfReader reader = new PdfReader("C:\\Users\\asfs\\Downloads\\1013-Form22.pdf");
String name = "C:\\Users\\asfs\\Downloads\\Temp.pdf";
PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(name));
AcroFields form = stamp.getAcroFields();
String last = "Form22_Dtls[0].Page1[0].Country_C[0]";
form.setField(last, "Sample Country name");
HashMap map = new HashMap();
map = form.getFields();
Iterator iterator = map.keySet().iterator();
while(iterator.hasNext())
System.out.println("Field is >>>"+iterator.next());
// close pdf stamper
stamp.setFormFlattening(true);
stamp.close();
Please help me.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试:
PdfStamper 需要处于追加模式。
Try:
The PdfStamper needs to be in append mode.
如果您想要 Java 代码,这里是我从博客中获得的一个片段。但它使用 pdf Nitro,以防万一这有帮助或让我知道
它是使用 Java 直接从数据库检索数据的 Pdf 表单填写,希望它有效
访问自动填写表单的 Java 代码
if you want a Java code, here's a snippet I got from one a blog. But it uses pdf Nitro, in case this helps or let me know
It's Pdf form filling using Java that directly retrieves data from database, hope it works
Visit Java Codes for Automatic form fill
据我所知, stamp.setFormFlattening(true);您正在调用,删除字段并将其替换为内容,这就是您的新文档不保留字段的原因
as far as i know, the stamp.setFormFlattening(true); you are calling, remove fields and replace that with content, that's why your new document doesn't preserve fields