Hello,

                I am trying to use IText to populate a PDF form.  I am able to 
accomplish this as expected however when closing the PDFStamper, I receive the 
"[Fatal Error] :1:1: Content is not allowed in prolog." error.   This started 
occurring when I modified a PDF Form.  Previously the form had more fields to 
fill but I needed to change the field names or add new fields.  Either way I 
tried to accomplish this resulted in that error.  I am able to edit the actual 
PDF text but I am not able to edit the form fields or add form fields.

                Any help on this matter would be greatly appreciated.

Code:

        try
        {
            PdfReader pdfReader = new PdfReader(this.getTemplateFullFile());
            PdfStamper pdfStamper = new PdfStamper(pdfReader, new 
FileOutputStream(this.getFilledFullFile()));
            AcroFields pdfFormFields = pdfStamper.getAcroFields();
            pdfStamper.setFormFlattening(false);
            for (int i=0; i<pdfValues.size(); i++){
                ArrayList tempArray = pdfValues.get(i);
                String tArray0 = tempArray.get(0).toString();
                String tArray1 = tempArray.get(1).toString();
                if (tempArray.get(0).toString().equals("rbField") && 
!tempArray.get(0).toString().equals("1") && 
!tempArray.get(0).toString().equals("2")){
                    this.setPeriodic(true);
                }else{
                    try{
                        if (tArray0.contains("ddress")){
                            pdfFormFields.setField(tArray0, tArray1);
                            }else{
                            pdfFormFields.setField(tArray0, tArray1);
                        }
                    }
                    catch(IOException e){e.printStackTrace();}
                    catch(DocumentException e){e.printStackTrace();}
                }
            }
            pdfStamper.setFormFlattening(true);
            try{
                pdfStamper.close();
                pdfReader.close();
            }
            catch(Exception e){e.printStackTrace();}
        }
        catch (IOException e){
            e.printStackTrace();
        }
        catch (Exception e)
        {
            System.out.println("\n\nPDFReader Problem: "+e.getMessage()+"\n\n");
        }

Joe Lazarski
Developer
Ad-Base Solutions | Turning Challenges into Solutions.
Eight Penn Center West
Suite 101
Pittsburgh, PA 15276
P 412.440.2011
C 412.651.6336
jose...@adbasesolutions.com<mailto:jose...@adbasesolutions.com>
Visit us at AdBaseSolutions.com <http://www.adbasesolutions.com/>

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
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

Reply via email to