Reputation: 748
I have a PDF file with some form fields that I need to fill in from Java code. I use iText 2.1.7 library for this, and this code:
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). 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:
applicationPrepaid[0].#pageSet[0].Pagina1[0].txtFirstName[0]
Pdftk tool gave me just txtFirstName
for the field name. I tried both the full name, and just txtFirstName
and it doesn't work. Help?
Upvotes: 1
Views: 1365
Reputation: 56
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. I think it's the 'pound' (#) sign that causes the error.
Upvotes: 1