1 Reply Latest reply on Jun 4, 2009 5:18 AM by Cy~p~riS

    reading xml data into a pdf and populating form fields

    garek007 Level 1

      I saw an old post, two years old, by Thom Parker saying it can't be done.  You can read the xml, but not populate form fields.  I'm using acrobat 7, is that still the case?  I need to find a way to write out a bunch of info in a text file and read it into a pdf and then fill in certain fields.  What's the best way to do that?

       

      Thanks,

      Stan

        • 1. Re: reading xml data into a pdf and populating form fields
          Cy~p~riS

          You mean you want to read an xml file into a pdf document then extract xml values and populate form fields this should help, but

          im doing this script from folder level,

           

          what i have is a xml file called test.xml on my local file system, it contains the folowing xml

           

           

          <?xml version="1.0" encoding="utf-8" ?>

              <session>
              <details>
                     <name>Kyle</name>
                     <datetime>Thu Jun 4 2009</datetime>
            </details>
          </session>
          then i have my folder level script, you could attach the same code to a button, if you wanted the
          user to first click on a button or field to populate the fields on the form.
          var importTestXML = app.trustedFunction(
            function() {
                app.beginPriv();
               
                  try {
                    this.importDataObject("MyData", "/C/test.xml");
                   
                    // Get The Objects Contents
                    var oDB = this.getDataObjectContents("MyData");
                   
                    // Convert to a string
                    var cDB = util.stringFromStream(oDB, "utf-8");
                    console.println("CONVERETED: " + cDB);
                   
                    // Send to function to Strip XML Nodes
                    var myXML = XMLData.parse(cDB, false);
                   
                    // Extract XML node values like this
                    var tName = myXML.session.details.name;
                    var tDate = myXML.session.details.datetime;
                   
                    // Populate form fileds like this
                    this.getField("edtFirstName").value = tName.value;
                    this.getField("edtDate").value = tDate.value;

                  } catch (e) {
                    app.alert(e);
                    console.println(e);
                  }     
                  app.endPriv();
            }
          );