10 Replies Latest reply on Dec 21, 2010 5:09 AM by try67

    How read data from external files  to  pdf form?

    skiner2010

      Hi,

      Im  new on adobe acrobat software, but i want creat simple pdf file with form (select, and  textarea),

      I know how add this elements for docmet,  and  set some value to  'select' element, but I want  read data form txt files from local hard drive and ,  set this data as value (for select element).

       

       

      I write  some like this:

       

      //-------------------------------------------------------------
      //-----------------Do not edit the XML tags--------------------
      //-------------------------------------------------------------

       

      //<AcroForm>
      //<ACRO_source>Text1:Annot1:MouseUp:Action1</ACRO_source>
      //<ACRO_script>
      /*********** belongs to: AcroForm:Text1:Annot1:MouseUp:Action1 ***********/

       

       

      function readJs(){
      var myFileSysObj = new ActiveXObject("Scripting.FileSystemObject");
      var myInputTextStream = myFileSysObj.OpenTextFile("c:\\temp\\test.txt", 1, true);
      var line;
      var temp;
          while(!myInputTextStream.AtEndOfStream){
            line =myInputTextStream.ReadLine();
            temp = line.split(";");
            one.value=temp[0];
          }
          myInputTextStream.Close();
        }

       

       

      var one = this.getField("Text1");

       

      if (one.value == 'one') {

       

          read();

       

      }

       

      //</ACRO_script>
      //</AcroForm>

       

       

      but I have error about ActiveXObject,

       

       

      so I try to  write some like this:

       

      //-------------------------------------------------------------
      //-----------------Do not edit the XML tags--------------------
      //-------------------------------------------------------------

       

      //<AcroForm>
      //<ACRO_source>Text1:Annot1:MouseUp:Action1</ACRO_source>
      //<ACRO_script>
      /*********** belongs to: AcroForm:Text1:Annot1:MouseUp:Action1 ***********/

       

       

      function read(){
          var temp;

       

           //data from txt file
          var data=new Array(
                "data1;data2,data3";

                "data21;data22;data23";
          )


          for (var el in data){
              temp=el.split(";");
              one.value=temp[0];
          }
      }

       

      var one = this.getField("Text1");

       

      if (one.value == 'one') {
          read();
      }

      //</ACRO_script>
      //</AcroForm>

       

      and  I have this exception:

       

      Acrobat JavaScript Debugger Functions Version 9.0
      Acrobat EScript Built-in Functions Version 9.0
      Acrobat Annotations / Collaboration Built-in Functions Version 9.0
      Acrobat Annotations / Collaboration Built-in Wizard Functions Version 9.0
      Acrobat SOAP 9.0
      Exception in line 14 of function read, script Field:Mouse Up
      Exception in line 70 of function top_level, script Field:Mouse Up

       

      InvalidSetError: Set not possible, invalid or unknown.
      Field.value:14:Field Text1:Mouse Up

       

       

       

      Can anyone helpme?

      How read data from file and set it as forms  elements value?

       

       

      TIA

        • 1. Re: How read data from external files  to  pdf form?
          try67 MVP & Adobe Community Professional

          Read in the Acrobat JavaScript reference file about the Data Object and the

          Doc object's methods related to it, such as importDataObject and

          getDataObjectContents.

          • 2. Re: How read data from external files  to  pdf form?
            skiner2010 Level 1

            Can You give me any links to some resorce or ebook ?

            • 4. Re: How read data from external files  to  pdf form?
              skiner2010 Level 1

              OK,

              can you write me  some simply way to catch this exception, or what i must change in my OS settings or st. else... because, i have:

              //-------------------------------------------------------------
              //-----------------Do not edit the XML tags--------------------
              //-------------------------------------------------------------

               

              //<AcroForm>
              //<ACRO_source>Text1:Annot1:MouseUp:Action1</ACRO_source>
              //<ACRO_script>
              /*********** belongs to: AcroForm:Text1:Annot1:MouseUp:Action1 ***********/
              var one = this.getField("Text1");
              var two = this.getField("Text2");
              var three = this.getField("Text3");

               

              if (one.value == 'one') {
                  two.value='500'
                  three.value='ddd'
                  //read();
                  this.importDataObject("myFile", "D:\test\testdata.csv");
                  var myData = this.getDataObject("myFile");
                  for (var i in myData)
                  console.println(myData[i]);
                 
              } else if (one.value == 'two') {
                  two.value='300'
                  three.value='sss'
              }
              //</ACRO_script>
              //</AcroForm>

               

              When I try"run" this i have this exception:

               

              NotAllowedError: Security settings prevent access to this property or method.
              Doc.importDataObject:68:AcroForm:Text1:Annot1:MouseUp:Action1
              Exception in line 68 of function top_level, script AcroForm:Text1:Annot1:MouseUp:Action1

               

              NotAllowedError: Security settings prevent access to this property or method.
              Doc.importDataObject:68:AcroForm:Text1:Annot1:MouseUp:Action1
              Exception in line 68 of function top_level, script AcroForm:Text1:Annot1:MouseUp:Action1

               

              NotAllowedError: Security settings prevent access to this property or method.
              Doc.importDataObject:68:AcroForm:Text1:Annot1:MouseUp:Action1

               

               

              on manual ebook i see this info:

              http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/wwhelp/wwhimpl/common/html/w whelp.htm?context=Acrobat9_HTMLHelp&file=JavaScript_SectionPage.70.1.html

               

               

              but I don't see any solution.

              TIA

              • 5. Re: How read data from external files  to  pdf form?
                try67 MVP & Adobe Community Professional

                Read the security restrictions for this method.

                Also, your cDIPath parameter is incorrect.

                • 6. Re: How read data from external files  to  pdf form?
                  skiner2010 Level 1

                  ok,

                  thanks for reply,  im start searching some info about security restrictions.


                  Is this correct? right?

                      this.importDataObject("myFile", "/d/test/testdata.csv");

                  • 7. Re: How read data from external files  to  pdf form?
                    skiner2010 Level 1

                    Hi,

                    Can you give me some exemple code how  read data from file?

                     

                    I write file config.js on  c:\program files\adobe\acrobat ...\javascript\config.js

                     

                     

                    on this file i have this code :


                    trustedActiveDocs = app.trustedFunction (
                    function()
                        {
                        app.beginPriv(); // Explicitly raise the privilege
                            this.importDataObject("myFile", "/d/test/testdata.csv");
                            var myData = this.getDataObject("myFile");
                            for (var i in myData)
                            var d = myData[i];
                        app.endPriv();
                            return d;


                        }
                    );

                     

                     

                     

                     

                    and on  JS in pdf :

                     

                     

                    //-------------------------------------------------------------
                    //-----------------Do not edit the XML tags--------------------
                    //-------------------------------------------------------------

                     

                    //<AcroForm>
                    //<ACRO_source>Text1:Annot1:MouseUp:Action1</ACRO_source>
                    //<ACRO_script>
                    /*********** belongs to: AcroForm:Text1:Annot1:MouseUp:Action1 ***********/
                    var one = this.getField("Text1");
                    one.value =trustedActiveDocs();

                     

                     

                     

                     

                    and when I try  click  on select item in my pdf file I have this error

                     

                    Acrobat JavaScript Debugger Functions Version 9.0
                    Acrobat EScript Built-in Functions Version 9.0
                    Acrobat Annotations / Collaboration Built-in Functions Version 9.0
                    Acrobat Annotations / Collaboration Built-in Wizard Functions Version 9.0
                    Acrobat SOAP 9.0
                    Exception in line 2 of function top_level, script Field:Mouse Up


                    InvalidSetError: Set not possible, invalid or unknown.
                    Field.value:2:Field Text1:Mouse Up

                     

                     

                     

                    My question is,

                    how open text file  get line, next explode it and use to set as value  to my input and select item on pdf file.

                     

                    some like.

                    var long_string= fgets(file_handler,other_options);

                    var array =  long_string.split("");

                     

                    and next use array[x]  to  set  as value in pdf body.

                     

                     

                     

                    If  I modify my  script :

                     

                    config.js:

                     

                     

                    trustedActiveDocs = app.trustedFunction (
                    function()
                        {
                        app.beginPriv(); // Explicitly raise the privilege
                            this.importDataObject("myFile", "/d/test/testdata.csv");
                            var myData = this.getDataObject("myFile");
                            var array =myData.split("");
                           
                        app.endPriv();
                            return array;

                     

                        }
                    );

                     

                     

                    pdf js:

                     

                     

                    var one = this.getField("Text1");
                    var temp =trustedActiveDocs();

                     

                    one.value = temp[0];

                     

                     

                     

                     

                     

                     

                    I can see this exception :/

                     

                    Acrobat JavaScript Debugger Functions Version 9.0
                    Acrobat EScript Built-in Functions Version 9.0
                    Acrobat Annotations / Collaboration Built-in Functions Version 9.0
                    Acrobat Annotations / Collaboration Built-in Wizard Functions Version 9.0
                    Acrobat SOAP 9.0

                     

                    myData.split is not a function
                    7:Field:Mouse UpException in line 7 of function anonymous, script Folder-Level:App:config.js
                    Exception in line 2 of function top_level, script Field:Mouse Up

                     

                    myData.split is not a function
                    7:Field:Mouse Up

                    • 8. Re: How read data from external files  to  pdf form?
                      dying veteran Level 1

                      Where do you come up with readLine() ?

                       

                      As I explained to Francis Fukuyama, you need a

                       

                      dot value

                       

                      method like this

                       

                       

                       

                      console.println( this.getField("identifier").value )

                       

                      will give you the value and its POC  but I dont know how you can do this without making a field somewhere ... maybe hidden ............

                       

                       

                       

                       

                      [signature deleted by host]

                      • 9. Re: How read data from external files  to  pdf form?
                        FrancisFukuyama

                        what happened to the other three replies by maxwyss try67 etc ? last I saw there were 13 replies. How to delete your posts ?

                        [post edited by host]

                        • 10. Re: How read data from external files  to  pdf form?
                          try67 MVP & Adobe Community Professional

                          Could you not copy&paste the entire page when replying? You're screwing up the threads.