3 Replies Latest reply on May 12, 2011 5:20 PM by gkaiseril

    Populate a text field with contents of a file ?

    gapsys

      Hi,

      Is it possible in Acrobat / LiveCycle designer ( v9 ) to create a button on a Form that will

      • Open a file
      • Read its contents into a variable
      • Close the file
      • Place the contents into a field on the form ?

      I am struggling to get the correct JavaScript syntax for Opening the file ( eg H:\PA2011\Report.txt ).

       

      I am new to LiveCycle designer/Acrobat  & JavaScript syntax & have not found any discussions on the forums with examples.

       

      Thanks

        • 1. Re: Populate a text field with contents of a file ?
          gkaiseril MVP & Adobe Community Professional

          The PDF file standard does not use the Windows disk drive mapping policy within the PDF. Check the PDF Reference Manual.

           

          Unless you want to parse a text file, look at using a tab delimited file and use the 'importTextData" method.

           

          From the Acrobat JS API Reference:

           

          Example 1

           

          In this example, there are text fields named "First", "Middle", and "Last", and a data file whose first row consists of the three strings, "First", "Middle", and "Last", separated by tabs, along with four additional rows of tab-separated name data.

          First Middle Last

          A. C. Robat

          T. A. Croba

          A. T. Acrob

          B. A.  Tacro

           

          // Import the first row of data from "myData.txt".

          this.importTextData("/c/data/myData.txt", 0)

           

          Example (continued)

           

          The following code is a mouse-up action for a button. Clicking on the button cycles through the text file and populates the three fields "First", "Middle", and "Last" with the name data.

           

          if (typeof cnt == "undefined") cnt = 0;

          this.importTextData("/c/data/textdata.txt", cnt++ % 4)

           

          1 person found this helpful
          • 2. Re: Populate a text field with contents of a file ?
            gapsys Level 1

            GKaiseril,

            Thanks for your suggestion.

            I had tried the same code from the API reference book but was using it in LiveCycle not Acrobat which was the problem.

             

            Turns out ( found out form LiveCyele tech support) that the Acrobat Javascript APIs do not work in LiveCycle.

            They sent me a LiveCycle specific document "LiveCycle® Designer ES Scripting Reference" which I am going thru.

             

            Thanks

            • 3. Re: Populate a text field with contents of a file ?
              gkaiseril MVP & Adobe Community Professional

              If you carfeully read the reverence you should find a list the Acrobat JS items that work in LiveCycle Designer. And some that can not run directly in LiveCycle Designer can be accessed by programing folder level JS functions. If you run the Acrobat JS code make sure you chose the language in LiveCycle Designer to be JavaScript and not FormCalc.

               

              importTextData is supported in LiveCycle Designer. See "JavaScript objects from Acrobat supported in Designer ES2" in the LiveCycle Designer Scripting Reference.

               

              This forum is for Acrobat JavaScript. There are a number of forums for LIveCycle Designer products.