• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Pass argument to event.target.buttonImportIcon()

New Here ,
Sep 02, 2020 Sep 02, 2020

Copy link to clipboard

Copied

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!!

TOPICS
Acrobat SDK and JavaScript

Views

854

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 02, 2020 Sep 02, 2020

Copy link to clipboard

Copied

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_Acro...

 

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 02, 2020 Sep 02, 2020

Copy link to clipboard

Copied

Read the highlighted part carefully:

 

try67_0-1599076742567.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 02, 2020 Sep 02, 2020

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 02, 2020 Sep 02, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 02, 2020 Sep 02, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 02, 2020 Sep 02, 2020

Copy link to clipboard

Copied

Read the reply of Thom Parker.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 02, 2020 Sep 02, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 02, 2020 Sep 02, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 02, 2020 Sep 02, 2020

Copy link to clipboard

Copied

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

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 02, 2020 Sep 02, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 02, 2020 Sep 02, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 02, 2020 Sep 02, 2020

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 02, 2020 Sep 02, 2020

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 02, 2020 Sep 02, 2020

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 03, 2020 Sep 03, 2020

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 03, 2020 Sep 03, 2020

Copy link to clipboard

Copied

Not possible. The user has to click OK to accept the entered value.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 03, 2020 Sep 03, 2020

Copy link to clipboard

Copied

LATEST

Thanks try67.  I assume that a custom response box can be built, but this is close enough for now.  

 

I'm also gonna implement your work-around for non-acrobat readers that don't support javascript.  Found that this morning.  That is presenting a problem for me when distributed to clients.  I'm gonna include a link to Adobe in the text field to download the reader as a solution.

Thanks for that advice as well.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 02, 2020 Sep 02, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines