Skip to main content
Known Participant
Sep 2, 2020 7:51 PM UTC
Question

Pass argument to event.target.buttonImportIcon()

Hi.  I'm trying to import an image into an image field on a form by passing an argument.  The argument is the fully qualified path + file.  I saw the following short script in a post and I am trying to tweak it to make it work ...

 

var a =this.getField ("Hidden Text").valueAsString;

var b =this.getField ("Application Images(Screenshots)").valueAsString;

event.target.buttonImportIcon(a+b);

 

I have also tried to hard code the argument, and the field will not accept the image. 

[ event.target.buttonImportIcon("/C/myPath/Image1.jpg"); ]

I get nothing ... Any suggestions would be much appreciated.  Thanks!!

This topic is closed to new replies. Start a new post to keep the conversation going.

18 replies

Known Participant
Sep 3, 2020 1:36 AM UTC

Your approach is alot simpler than what I was working on.  LOL!  I got everything but the leading"/" and the ":".

Works great ... Thanks Thom!

----------------------------------

this.getField("fileStringParsed").value = newString;

var str = this.getField("FileString").value;

var wordArray = str.split("\\");

var wordIndex = wordArray.length - 1;

str = "";

for (i=0; i < wordIndex; i++) {

    str += wordArray[i] + "/";

}

this.getField("fileStringParsed").value = str + wordArray[wordIndex];

Translate
Known Participant
Sep 3, 2020 12:20 AM UTC

Thanks.  Sounds like a clean approach.  If you have any good quick references or samples, it would be appreciated.  

Next hurdle will be parsing:

"C:\Users\Me\Documents\F1\F2\Images\Image_1.JPG"

to

"/C/Users/Me/Documents/F1/F2/Images/Image_1.JPG"

If you can point me to any tools / methods / utilities, I would greatly appreciate that as well.  Thanks try67!

Translate
Thom Parker
Community Expert
Community Expert
Sep 3, 2020 1:15 AM UTC

Here's an article on using the Response Box

https://acrobatusers.com/tutorials/popup_windows_part2/

 

And you should look it up in the Acrobat JavaScript Reference.

 

Use a regular expression replace to do an easy conversion, based on the path always being a full windows path. 

 

var strDIPath = "/" + strPlatPath.replace(/\:?\\/g,"/");

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Known Participant
Sep 3, 2020 2:00 PM UTC

Thanks Thom.  Easy implementation.  I'm almost satisfied with the functionality.

Is there a way to force an acceptText() type method on the paste into cRtn to eliminate the additional click?  Then I would like to hide/disable the [OK] button.

Translate
Known Participant
Sep 2, 2020 8:41 PM UTC

Thanks try67.  This is only going to be executed on my console.  It worked.

Translate
Known Participant
Sep 2, 2020 8:53 PM UTC

Sorry try67.  Understand your "paste" comment.  Thanks.  Gonna look at using a text field to paste to and possibly invoke the Import. 

Translate
try67
Community Expert
Community Expert
Sep 2, 2020 9:44 PM UTC

You can also use an app.response() window to prompt the user to paste the copied text, and then you'll be able to use it in the rest of your code. That way you can do it all from the button field.

Translate
Known Participant
Sep 2, 2020 8:39 PM UTC

Thanks Bernd, and of course Thom.  That worked.  Didn't see that at first.

Nesa ... "ImportIcon" worked.  "GetIcon" not in this scenario.

Translate
Known Participant
Sep 2, 2020 8:31 PM UTC

This is where I want to get (big picture) ... clearly beyond just javascript/acrobat ...

Want to copy the fully qualified path/file from windows explorer to clipboard, with minimal effort (one or two clicks?)

Execute [mouse up] script on the image field to accept the clipboard contents to a variable and then use button(Import/Get)Icon() to populate the field.  Thanks!

 

I

Translate
try67
Community Expert
Community Expert
Sep 2, 2020 8:36 PM UTC

You can't use a script to paste anything, neither image nor text. It has to be done manually by the user.

Translate
Known Participant
Sep 2, 2020 8:21 PM UTC

Thanks for the quick reply!  Turned on menu privileges.  Did not work.  Also tried turning off global security policy ... NG.

Translate
Bernd Alheit
Community Expert
Community Expert
Sep 2, 2020 8:25 PM UTC

Read the reply of Thom Parker.

Translate
Nesa Nurani
Community Expert
Community Expert
Sep 2, 2020 8:18 PM UTC

Hi, have you consider a workaround instead of buttonImportIcon to use buttonGetIcon() , with hidden button field?

Translate
Thom Parker
Community Expert
Community Expert
Sep 2, 2020 8:00 PM UTC

If you want to pass a path parameter to the import function, then the user has to do something to create trust. For example, adding the PDF to the set of trusted documents in enhanced security, or installing a folder level script. 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
Community Expert
Sep 2, 2020 7:59 PM UTC

Read the highlighted part carefully:

 

 

Translate
Thom Parker
Community Expert
Community Expert
Sep 2, 2020 7:57 PM UTC

Using the "Path" parameter in this function require Privilege, i.e. it is restriced for security reasons. 

Here's the reference entry:

https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/#t=Acro12_MasterBook%2FJS_API_AcroJS%2FField_methods.htm%23TOC_buttonImportIconbc-4&rhtocid=_6_1_8_31_2_3

 

Here's an article that discusses "trust/privilege" in Acrobat Scripts.

https://www.pdfscripting.com/public/Trust-and-Privilege-in-Acrobat-Scripts.cfm

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often