Quantcast
Channel: Aspose.Pdf Product Family
Viewing all articles
Browse latest Browse all 3131

Not seeing all fields in PDF

$
0
0
I'm converting from iTextSharp to Aspose.PDF using a function to populate form elements and then flatten the form.
I have a PDF template with several form fields in it.  iTextSharp recognizes all of the fields and Acrobat recognizes all of them as well.
But when using Aspose.PDF, it only seems to recognize 4 of the fields.

The method I am using to populate the form fields looks like this:

      public bool popPDFData(string templatefile, string destfile, Hashtable values, bool lockfields)
      {
         Document pdfreader = new Document(templatefile);
         StringBuilder warnings = new StringBuilder();
         foreach (Field fld in pdfreader.Form)
         {
            try
            {
               if(fld.IsGroup) {
                  foreach (Field cfld in fld)
                  {
                     string fldname = cfld.Name;
                     if (string.IsNullOrEmpty(fldname))
                     {
                        fldname = cfld.PartialName;
                     }
                     cfld.Value = (string)values[fldname];
                     cfld.Contents = (string)values[fldname];
                  }
               }
               else 
               {
                  string fldname = fld.Name;
                  if(string.IsNullOrEmpty(fldname)) {
                     fldname = fld.PartialName;
                  }
                  fld.Value = (string)values[fldname];
                  fld.Contents = (string)values[fldname];
               }
            }
            catch (Exception ppde)
            {
               warnings.Append("Unable to set field " + fld + " to a value of " + (string) values[fld] + " - " + ppde.ToString() + "\r\n");
            }
         }
         if (warnings.Length > 0)
         {
            TVUtils.LogWarning("Problems populating data using template " + templatefile + " saving as " + destfile + "\r\n" + warnings.ToString());
         }
         if(lockfields) {
            pdfreader.Flatten();
         }
         pdfreader.Save(destfile);
         pdfreader.Dispose();
         return true;
      }


(Note that the catch statement is never being hit when I step through the code)

The code I am using the test the above method is:

string templatepath = "D:\\topvuecode\\pdftest\\CDAform.pdf";
string destpath = "D:\\tvattachments\\testpdf123.pdf";

PDFUtils pdfutil = new PDFUtils();
string[] fields = pdfutil.getFormFieldList(templatepath);

Hashtable values = new Hashtable();
values.Add("TO", "123 Sesame Street");
values.Add("FROM", "21 Jump Street");
values.Add("CONTRACT NUMBER", "abcdefghijklmnop");
values.Add("LINE ITEM", "001");
values.Add("CDA NO", "123456");
values.Add("OPR", "OPR val here");
values.Add("SPO SUSPENSE", "11-JUL-2014");
values.Add("DATE INITIATED", "19-JUL-2014");

pdfutil.popPDFData(templatepath, destpath, values, false);


The PDF template that I am using is attached here.

Am I doing something wrong to be able to see all of the form fields on the PDF?  Or is there some other reason that Aspose.PDF does not recognize all of the fields on the form?

Thank you



Viewing all articles
Browse latest Browse all 3131

Trending Articles