Skip to main content
Known Participant
September 2, 2020
Question

Pass argument to event.target.buttonImportIcon()

  • September 2, 2020
  • 10 replies
  • 1854 views

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 has been closed for replies.

10 replies

Known Participant
September 3, 2020

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

Known Participant
September 3, 2020

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!

Thom Parker
Community Expert
Community Expert
September 3, 2020

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,"/");

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Known Participant
September 3, 2020

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.

Known Participant
September 2, 2020

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

Known Participant
September 2, 2020

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

try67
Community Expert
Community Expert
September 2, 2020

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.

Known Participant
September 2, 2020

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

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

Known Participant
September 2, 2020

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

try67
Community Expert
Community Expert
September 2, 2020

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

Known Participant
September 2, 2020

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

Bernd Alheit
Community Expert
Community Expert
September 2, 2020

Read the reply of Thom Parker.

Nesa Nurani
Community Expert
Community Expert
September 2, 2020

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

Thom Parker
Community Expert
Community Expert
September 2, 2020

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. 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
Community Expert
September 2, 2020

Read the highlighted part carefully:

 

 

Thom Parker
Community Expert
Community Expert
September 2, 2020

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

 

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