Awesome! Thanks a lot Bruno - you guys are the best.

Gylfi 

-----Original Message-----
From: 1T3XT info [mailto:i...@1t3xt.info] 
Sent: Monday, November 23, 2009 10:06 AM
To: Post all your questions about iText here
Subject: Re: [iText-questions] AcroForm with empty Fields array


Gylfi Ingvason wrote:
> Thanks Leonard.
> 
> Since that is the case, I would suggest that the flatten form code in 
> the PdfStamper be amended to take that into account.

Found it! But some changes are needed.
The comments are in Dutch, and the code assumes that all the annotations in
each page are widget annotations.
I should clean the code up and add more checks.

public static void main(String[] args)
   throws IOException, DocumentException {
   PdfReader reader = new PdfReader("sworn_DOWA_en.pdf");
   // formulier ophalen
   PdfDictionary root = reader.getCatalog();
   PdfDictionary form = root.getAsDict(PdfName.ACROFORM);
   PdfArray fields = form.getAsArray(PdfName.FIELDS);
   // fields is leeg en dit zou niet mogen
                
   // pagina's ophalen
   PdfDictionary pages = root.getAsDict(PdfName.PAGES);
   PdfArray kids = pages.getAsArray(PdfName.KIDS);
   PdfDictionary page;
   // annotaties van de pagina toevoegen als form fields
   PdfArray annots;
   for (int i = 0; i < kids.size(); i++) {
     page = (PdfDictionary)kids.getDirectObject(i);
     annots = page.getAsArray(PdfName.ANNOTS);
     for (int j = 0; j < annots.size(); j++) {
       fields.add(annots.getPdfObject(j));
     }
   }
   // de gewijzigde file saven
   PdfStamper stamper = new PdfStamper(reader,
     new FileOutputStream("new_form.pdf"));
   stamper.close();
        
   // testen welke velden er gevonden worden
   reader = new PdfReader("new_form.pdf");
   AcroFields formfields = reader.getAcroFields();
   for (Iterator i = formfields.getFields().keySet().iterator();
     i.hasNext();) {
     System.out.println(i.next());
   }
}

----------------------------------------------------------------------------
--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus
on what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions:
http://www.1t3xt.info/examples/ You can also search the keywords list:
http://1t3xt.info/tutorials/keywords/



------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to