Search code examples
pdfmethodsadobe-reader

How to get the path of an Image Field in a pdf form, in Adobe?


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';


Solution

  • 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