The code looks ok. The only reason I can see for failure is if the field
names you are giving do not match the ones at the document. You can get the
field names of the document with AcroFields.getFields(), the keys are the
field names. When calling setField() check the return value, it's true if
the field was updated or false if the field was not found.

Best Regards,
Paulo Soares

----- Original Message -----
From: "Tony Costanzo" <[EMAIL PROTECTED]>
To: "Paulo Soares" <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Friday, March 07, 2003 16:23
Subject: RE: [iText-questions] itext-paulo-110 (2003-03-05)


> Paulo-
>
> Here is a method I wrote to process a number of pdfs with their own data
and
> merge them into one pdf.  When this pdf is generated all the pages of pdf
> show up correctly, but the form fields are not populated.
>
> Thanks in advance.
>
> Tony
>
>
> /**
>  * @param pdfFiles <code>List</code> contains a list of HashMaps which
> contains
>  * values for a pdf template and template value map which contains data to
> be
>  * populated on that pdf.
>  */
> public void processPDF(List pdfFiles, OutputStream outStream) throws
> Exception
> {
>
>         Document mergedPDF = new Document();
>
>         PdfCopy writer = new PdfCopy(mergedPDF, outStream);
>         mergedPDF.open();
>
>         Iterator iterator = pdfFiles.iterator();
>
>         while(iterator.hasNext())
>         {
>             HashMap pdfFile = (HashMap) iterator.next();
>             String pdfDirectory =
>
"d:\\web\\apps\\war-dir\\ins_efile_service_center\\private\\pdfs\\templatePD
> F\\";
>             String templateName = pdfDirectory + (String)
> pdfFile.get("TEMPLATE_NAME");
>             System.out.println("Template="+templateName);
>             Map valueMap = (Map) pdfFile.get("TEMPLATE_VALUE_MAP");
>
>             PdfReader singlePDF = new PdfReader(templateName);
>             ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
>
>             PdfStamper stamp = new PdfStamper(singlePDF, pdfStream);
>
>             AcroFields form = stamp.getAcroFields();
>             HashMap formFields = form.getFields();
>
>             Set formFieldNames = formFields.keySet();
>             Iterator nameIterator = formFieldNames.iterator();
>
>             while(nameIterator.hasNext())
>             {
>                String fieldStringValue = "";
>                String fieldName = (String) nameIterator.next();
>
>                Object value = valueMap.get(fieldName);
>
>                if(value != null)
>                {
>                    if(value instanceof Boolean)
>                    {
>                         Boolean boolValue = (Boolean) value;
>
>                         if(boolValue.booleanValue() == true)
>                         {
>                             fieldStringValue = "TRUE";
>                         }
>                         else
>                         {
>                             fieldStringValue = "FALSE";
>                         }
>                    }
>                    else if(value instanceof String)
>
>
>                         fieldStringValue = (String) value;
>                    }
>
>                    form.setField(fieldName, fieldStringValue);
>                    System.out.println("FieldName ="+fieldName +",
> value="+fieldStringValue);
>                }
>             }
>
>             stamp.setFormFlattening(true);
>
>             stamp.close();
>
>             PdfReader completedPDF = new
PdfReader(pdfStream.toByteArray());
>
>             int numPages = completedPDF.getNumberOfPages();
>             // step 4: we add content
>             PdfImportedPage page;
>
>             for (int i = 0; i < numPages; )
>             {
>                 ++i;
>                 page = writer.getImportedPage(completedPDF, i);
>                 writer.addPage(page);
>                 System.out.println("Processed page " + i);
>             }
>
>             PRAcroForm completedform = completedPDF.getAcroForm();
>             if (completedform != null)
>                 writer.copyAcroForm(completedPDF);
>         }
>
>         mergedPDF.close();
>
>
>     }
>
>
>
>
> -----Original Message-----
> From: Paulo Soares [mailto:[EMAIL PROTECTED]
> Sent: Thursday, March 06, 2003 11:21 AM
> To: 'Tony Costanzo'; [EMAIL PROTECTED]
> Subject: RE: [iText-questions] itext-paulo-110 (2003-03-05)
>
>
> No. Each file is treated separately. For each file:
>
> - create a new PdfReader with the pdf template
>
> - create a new PdfStamper with the PdfReader
>
> - change the fields
>
> - flatten
>
> - close
>
> The resulting file, in disk or memory, is used to create a new PdfReader
> that will then be concatenated with CopyPdf or something inspired on it to
> make the additions dynamically.
>
> Best Regards,
> Paulo Soares
>
> > -----Original Message-----
> > From: Tony Costanzo [SMTP:[EMAIL PROTECTED]
> > Sent: Thursday, March 06, 2003 16:12
> > To: Paulo Soares; [EMAIL PROTECTED]
> > Subject: RE: [iText-questions] itext-paulo-110 (2003-03-05)
> >
> > Paulo-
> >
> > When you get the PDFStamper, get the AcroFields, set the Fields in the
> > AcroFields(), flatten the fields and close the PDFStamper, do you then
> > add the pages one by one from the PDFStamper to the new document and
then
> > add the acro fields to the new document?
> >
> > Thanks,
> > Tony
> >
> > -----Original Message-----
> > From: Paulo Soares [mailto:[EMAIL PROTECTED]
> > Sent: Thursday, March 06, 2003 5:15 AM
> > To: 'Tony Costanzo'; [EMAIL PROTECTED]
> > Subject: RE: [iText-questions] itext-paulo-110 (2003-03-05)
> >
> >
> > It can be done if you flatten the fields otherwise the field names would
> > be
> > duplicated. The sequence is:
> >
> > - Open the destination document (see CopyPdf.java)
> >
> > - while you have more data
> >
> > -    read the pdf template and create a PdfStamper instance
> >
> > -    populate the pdf fields (see PdfStamper.getAcroFields() and
> > AcroFields.setField())
> >
> > -    flatten the fields (see PdfStamper.setFormFlattening())
> >
> > -    close PdfStamper and append with CopyPdf
> >
> > Best Regards,
> > Paulo Soares
> >
> > > -----Original Message-----
> > > From: Tony Costanzo [SMTP:[EMAIL PROTECTED]
> > > Sent: Wednesday, March 05, 2003 21:39
> > > To: [EMAIL PROTECTED]
> > > Subject: [iText-questions] itext-paulo-110 (2003-03-05)
> > >
> > > In the new release it says there is support for form filling, form
> > > flattening, and FDF Merging.  Are there
> > > any examples of taking a an existing PDF, taking data and populating
> > > fields, repeating this process
> > > for the same PDF several times with different data (i.e. merging pdfs
> > with
> > > the same form fields) and
> > > then outputting one large merged PDF.  Can this be done with this
> > version?
> > > If so, can you point to
> > > what classes I need to be looking at.  Thanks in advance.
> > >
> > >
> > > Tony Costanzo
> > >
> > >
> > >
> > > Changes in itext-paulo-110 (2003-03-05)
> > >
> > > - Added support for form filling, form flattening and FDF merging.
> > >
> > > - fixed FontFactory to recognize fonts where the family is not a
> > >
> > > substring of the full name.
> > >
> > > - added ColumnText.getLinesWritten().
> > >
>



-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The debugger 
for complex code. Debugging C/C++ programs can leave you feeling lost and 
disoriented. TotalView can help you find your way. Available on major UNIX 
and Linux platforms. Try it free. www.etnus.com
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to