Why would the code below using the following field name cause this error?
Exception in thread "main" 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(Unknown
Source)
at com.sun.org.apache.xerces.internal.dom.ElementNSImpl.setName(Unknown
Source)
at com.sun.org.apache.xerces.internal.dom.ElementNSImpl.<init>(Unknown
Source)
at
com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.createElementNS(Unknown
Source)
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 PdfFormFiller.main(PdfFormFiller.java:48)
key = "form1[0].#subform[2].#field[95]"
//----------------CODE START -------------------------//
public static void main(String[] args) {
PdfReader reader = null;
PdfStamper stamp = null;
try {
reader = new PdfReader("Template.pdf");
stamp = new PdfStamper(reader, new
FileOutputStream("TemplateFilled.pdf"));
AcroFields form = stamp.getAcroFields();
HashMap fields = form.getFields();
String key;
for (Iterator i = fields.keySet().iterator(); i.hasNext(); ) {
key = (String) i.next();
switch(form.getFieldType(key)) {
case AcroFields.FIELD_TYPE_TEXT:
System.out.println("Processing " + key + ": ");
form.setField(key, "Test");
//<<<<<<<<<<<<<<<<<<<<<ERRORS HERE!
break;
default:
System.out.println("Skipping " + key);
break;
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
stamp.close();
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
reader.close();
}
//------------END CODE------------------//
Thanks
Howard
____________________________________________________________________________________
Special deal for Yahoo! users & friends - No Cost. Get a month of Blockbuster
Total Access now
http://tc.deals.yahoo.com/tc/blockbuster/text3.com
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Do you like iText?
Buy the iText book: http://www.1t3xt.com/docs/book.php
Or leave a tip: https://tipit.to/itexttipjar