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


Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter 
informação confidencial ou legalmente protegida. A incorrecta transmissão desta 
mensagem não significa a perca de confidencialidade. Se esta mensagem for 
recebida por engano, por favor envie-a de volta para o remetente e apague-a do 
seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de 
usar, revelar ou distribuir qualquer parte desta mensagem. 

Disclaimer:
This message is destined exclusively to the intended receiver. It may contain 
confidential or legally protected information. The incorrect transmission of 
this message does not mean the loss of its confidentiality. If this message is 
received by mistake, please send it back to the sender and delete it from your 
system immediately. It is forbidden to any person who is not the intended 
receiver to use, distribute or copy any part of this message.


-------------------------------------------------------------------------
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

Reply via email to