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!!
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:
Here's an article that discusses "trust/privilege" in Acrobat Scripts.
https://www.pdfscripting.com/public/Trust-and-Privilege-in-Acrobat-Scripts.cfm
Copy link to clipboard
Copied
Read the highlighted part carefully:
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.
Copy link to clipboard
Copied
Hi, have you consider a workaround instead of buttonImportIcon to use buttonGetIcon() , with hidden button field?
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.
Copy link to clipboard
Copied
Read the reply of Thom Parker.
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
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.
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.
Copy link to clipboard
Copied
Thanks try67. This is only going to be executed on my console. It worked.
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.
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.
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!
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,"/");
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.
Copy link to clipboard
Copied
Not possible. The user has to click OK to accept the entered value.
Copy link to clipboard
Copied
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.
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];