1

I am creating a PDF form using adobe reader. I have added an image field and a text box. The text box is read-only and I want to populate the text box with the path of the image selected by the end-user, in the image field. Following is my code:

var one = this.getField("Image1");
var two = this.getField("Text1");
two.value='The Path';

The above code runs normally but I can't figure out as to what to write instead of 'The Path', to get the actual path of the image selected by the end-user.

P.S.

On the Image1 button there are 2 actions:

  • Mouse Up(execute Js)

    event.target.buttonImportIcon();

  • On Blur(execute Js)

    var one = this.getField("Image1"); var two = this.getField("Text1"); two.value='The Path';

user3382203
  • 169
  • 1
  • 6
  • 25

1 Answers1

1

If I am understanding your request correctly... Assuming that Image1 is a button field and Text1 is a text field and you want the selected image file to appear as the button icon, the code would be as follows...

var one = this.getField("Image1");
var two = this.getField("Text1");
var doc = app.browseForDoc(); // Allows the user to browse for a file
var docPath = doc.cPath; // gets the file path of the selected file
one.buttonImportIcon(docPath); // uses the selected path to import the image as the "normal" or "up" button icon
two.value = docPath; // set the value of the text field to the selected device independent path
joelgeraci
  • 4,606
  • 1
  • 12
  • 19
  • The user is able to select the image and the value of the text1 is also updated. The problem is I need to get the path of the selected image. @joelgeraci, I have updated my question. – user3382203 Apr 02 '17 at 05:47
  • 1
    You can't get the path if you use buttonImportIcon() with no parameter. Add the code I provided to the Image1 MouseUp action. You won't need the OnBlur action. You can use my code as is or delete line one and change "one" in line 4 to "event.target" but the effect will be the same. – joelgeraci Apr 02 '17 at 16:40
  • Sure it does. How are you trying to execute it? – joelgeraci Apr 05 '17 at 18:19
  • Pasted your code in the Image1 button, MouseUp action. Nothing happens... I can't even select the image now, forget the path. – user3382203 Apr 06 '17 at 13:09
  • 1
    Ah - Ok - browseForDoc is a secure function so unless you create a privileged folder and run your PDF from there, it won't let you run the script by clicking the button. There are a few ways around this but that's the easiest. Unfortunately, there is no way to get the path and so it can be used by more than one other method any other way. You can also run the code from the JavaScript console and see that it works. – joelgeraci Apr 06 '17 at 16:45