We are trying to concatenate PDF pages generated dynamically, and show
different data in each page.
Each page should have its own unique set of 7 text fields. Using a sample 1
page pdf template, additional pages need to be generated dynamically under
certain conditions.

In our method logic, as the rename field to the left of the last dot is not
working, we are trying to remove the existing field and create a new field
in its place with a new text field name. It looks like the fields are not
getting removed ultimately from the page, and also they are getting added to
the wrong place ie. to page 1. The final PDF is generated with same data in
each page. In page 1,we can see the data is overlapping. (Though in the
debgugger, the fields are seen getting removed from memory and the fields
list)

Can someone give directions (sample snippet code would be helpful) on how
the TextFields can be renamed in different pages?  

See code snippet below corresponding to Text field.   

Method logic in summary:
1) First loop: a PdfReader list is created using the sample pdf template,
corresponding to N times.
2) Outside the second loop, an instance of  PdfCopyFields is created and
directed to byte array outputStream 
3) Second loop: For each reader in the reader list, we are trying to
"rename" the fields in the form.
PdfReader-> PdfStamper->PdfWriter->Acrofields to get the collection of
fields in each form.

As AcroFields renameField could not rename the part of the field name to the
left of the last dot., 
after Page 1 we are trying to remove the fields from memory and create new
fields using the property of the existing field.        
 
The completed Reader is added using CopyFields addDocument. the outputstream
is returned to the calling method. 
 
for (int i = 0; i < readerList.size(); i++) {

                PdfReader read = new PdfReader(new ByteArrayInputStream(b));
// b is the byte array of input pdf
                  baos.reset();
      
                    PdfStamper stamp = new PdfStamper(read, baos);
                    PdfWriter writer = stamp.getWriter();
                    AcroFields form1 = stamp.getAcroFields();

                    if (form1 != null && !form1.getFields().isEmpty()) {
                        HashMap fields = form1.getFields();

                        if (fields.size() > 0) {
                            Iterator keysItr = fields.keySet().iterator();
                            if (keysItr != null) {
                                while (keysItr.hasNext()) {      
                                    String curFieldName = (String)
keysItr.next();
                                    String newFieldName =
renameField(curFieldName, i);
                                    
                                    AcroFields.Item item = (AcroFields.Item)
fields.get(curFieldName);
                                    PdfDictionary dict = item.getWidget(0);
                                    PdfArray pdfArray =
dict.getAsArray(PdfName.RECT);

                                    float llx = 0;
                                    float lly = 0;
                                    float urx = 0;
                                    float ury = 0;

                                    ListIterator iter =
pdfArray.listIterator();
                                    if (iter != null) {
                                        int counter = 1;
                                        while (iter.hasNext()) {
                                            PdfNumber n = (PdfNumber)
iter.next();
                                            // set the rectangle coordinates
                                            if (counter == 1) {
                                                llx = n.floatValue();
                                                counter++;
                                            } else if (counter == 2) {
                                                lly = n.floatValue();
                                                counter++;
                                            } else if (counter == 3) {
                                                urx = n.floatValue();
                                                counter++;
                                            } else {
                                                ury = n.floatValue();
                                            }

                                        }

                                 keysItr.remove();

                               
                               TextField tf = new TextField(writer, new
Rectangle(llx, lly, urx, ury), newFieldName);
                                form1.removeField(curFieldName);
                                stamp.addAnnotation(tf.getTextField(), 1);      
                        
                                }

                                }  // while (keysItr.hasNext())
                            }
                        } // fields.size() > 0

                    }   //  if form1 != null ..

                    stamp.setFormFlattening(true);
                    stamp.close();

                    PdfReader completedReader = new
PdfReader(baos.toByteArray());
                   
                    copy.addDocument(completedReader);
                    completedReader.close();


                } 

Can someone give some hints or sample snippet code on how the TextFields can
be renamed in different pages?  
-- 
View this message in context: 
http://old.nabble.com/Renaming-TextFields-on-different-pages-using-iText-is-not-working..-tp26449014p26449014.html
Sent from the iText - General mailing list archive at Nabble.com.


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