If it's a static form with named fields it will work. iText works a lot better if it's not Designer, though.
Paulo ----- Original Message ----- From: "Howard Shank" <[EMAIL PROTECTED]> To: "Post all your questions about iText here" <[email protected]> Sent: Monday, March 31, 2008 7:15 PM Subject: Re: [iText-questions] Field name throws error. Thanks Paulo. I have no idea what that means yet! lol but I'll research it and see what I can figure out. I told my client to recreate the form using Adobe Acrobat and to NOT use designer so it can be manipulated. I'll wait and see what they say. In the mean time I'm trying to figure out how to use the iText Toolbox and RUPS. Thanks again for your help. Howard ----- Original Message ---- From: Paulo Soares <[EMAIL PROTECTED]> To: [email protected] Sent: Monday, March 31, 2008 11:01:15 AM Subject: Re: [iText-questions] Field name throws error. You PDF uses untitled field and those are not supported, I didn't even know that such a thing existed. Paulo > -----Original Message----- > From: Howard Shank [mailto:[EMAIL PROTECTED] > Sent: Monday, March 31, 2008 3:49 PM > To: Paulo Soares > Subject: Re: [iText-questions] Field name throws error. > > Paulo, > > I am unable to post the file publicly, but I'll send it to you here. > > When I change the # signs in the field name to # the > error goes away and the form processes without error. > > example: > String newkey = key.replace("#", "#"); > form.setField(newkey, "Test"); > > > Howard > > ----- Original Message ---- > From: Paulo Soares <[EMAIL PROTECTED]> > To: Post all your questions about iText here > <[email protected]> > Sent: Monday, March 31, 2008 10:32:45 AM > Subject: Re: [iText-questions] Field name throws error. > > As far as I know the character '#' is not special in XML. The error > happens when xerces is parsing XML that already exists in the PDF. > Please post the PDF if you want to continue this thread. > > Paulo > > > -----Original Message----- > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] On > > Behalf Of Howard Shank > > Sent: Monday, March 31, 2008 3:25 PM > > To: Post all your questions about iText here > > Subject: Re: [iText-questions] Field name throws error. > > > > Paulo, > > > > I know and agree that Xerces is throwing the actual error, > > but shouldn't iText handle the field name properly? > > > > If I get the field name from the AcroFields.getFields() > > collection and the field name contains a # sign, one would > > not expect that to use the AcroFields.setField() method that > > the # sign would have to be replaced with # before using > > the field name. After all, iText did return the name > > containing the #'s. > > > > Howard > > > > ----- Original Message ---- > > From: Paulo Soares <[EMAIL PROTECTED]> > > To: Post all your questions about iText here > > <[email protected]> > > Sent: Monday, March 31, 2008 9:38:07 AM > > Subject: Re: [iText-questions] Field name throws error. > > > > That's xerces complaining, not iText. The XML in your PDF has > > an error. > > > > Paulo > > > > > -----Original Message----- > > > From: [EMAIL PROTECTED] > > > [mailto:[EMAIL PROTECTED] On > > > Behalf Of Howard Shank > > > Sent: Monday, March 31, 2008 2:35 PM > > > To: Post all your questions about iText here > > > Subject: [iText-questions] Field name throws error. > > > > > > 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.checkQ > > > Name(Unknown Source) > > > at > > > com.sun.org.apache.xerces.internal.dom.ElementNSImpl.setName(U > > > nknown Source) > > > at > > > com.sun.org.apache.xerces.internal.dom.ElementNSImpl.<init>(Un > > > known Source) > > > at > > > com.sun.org..apache.xerces.internal.dom.CoreDocumentImpl.create > > > ElementNS(Unknown Source) > > > at > > > com.lowagie.text.pdf.XfaForm$Xml2SomDatasets.insertNode(Unknow > > > n 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 ------------------------------------------------------------------------- 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
