简体   繁体   English

PDF表格填写iText错误

[英]PDF form fill with iText error

I have a PDF file with some form fields that I need to fill in from Java code. 我有一个PDF文件,其中包含一些表单字段,需要从Java代码中填写。 I use iText 2.1.7 library for this, and this code: 我为此使用iText 2.1.7库,以及以下代码:

PdfReader reader = new PdfReader("C:\\Users\\igor\\Desktop\\test.pdf");
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("testout.pdf"), '\0', true);
AcroFields fields = stamper.getAcroFields();
fields.setField("txtFirstName", "Milan");
stamper.close();

and I get this error message: 我收到此错误消息:

org.w3c.dom.DOMException: INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified. 
at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.checkQName(CoreDocumentImpl.java:2582)
at com.sun.org.apache.xerces.internal.dom.ElementNSImpl.setName(ElementNSImpl.java:117)
at com.sun.org.apache.xerces.internal.dom.ElementNSImpl.<init>(ElementNSImpl.java:80)
at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.createElementNS(CoreDocumentImpl.java:2095)
at com.lowagie.text.pdf.XfaForm$Xml2SomDatasets.insertNode(Unknown Source)
at com.lowagie.text.pdf.AcroFields.setField(Unknown Source)
at com.lowagie.text.pdf.AcroFields.setField(Unknown Source)
at proba.main(proba.java:21)

The PDF is not created by me, so I don't know what type of form the file uses (if I understand correctly, there are FDF and XFA forms). PDF不是由我创建的,因此我不知道文件使用什么类型的表单(如果我理解正确,则有FDF和XFA表单)。 Since the PDF is not created by me, I used this tool http://support.persits.com/pdf/demo_formfields.asp to find out the names of the form fields, and it gave me this: 由于PDF不是我创建的,因此我使用了此工具http://support.persits.com/pdf/demo_formfields.asp来查找表单字段的名称,它为我提供了以下功能:

applicationPrepaid[0].#pageSet[0].Pagina1[0].txtFirstName[0]

Pdftk tool gave me just txtFirstName for the field name. Pdftk工具只给我txtFirstName作为字段名。 I tried both the full name, and just txtFirstName and it doesn't work. 我尝试了全名和txtFirstName ,但它不起作用。 Help? 救命?

The problem seems to lie in the fact that you are working with Basic pages. 问题似乎在于您正在使用“基本”页面。 The name '#pageSet[0' is the one causing the error. 名称“ #pageSet [0”是导致错误的名称。 I think it's the 'pound' (#) sign that causes the error. 我认为是导致错误的“磅”(#)号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM