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

How to execute a Trusted script on the open document ?

New Here ,
Dec 04, 2018 Dec 04, 2018

After a migration from win7 from win10, my team do not know how to execute the script anymore. Here is the script I want to execute, it should append another PDF to the end of document and send a mail (I did not write it) : https://justpaste.it/61gxj .

From what I understand from google, I have to put this script in C:\Users\UserName\AppData\Roaming\Adobe\Acrobat\Privileged\10.0\JavaScripts to be able to execute trusted methods/functions. Then, how do I actually use this function ? Is the path correct ? Thank you for your help, I'm really new to this.

Edit :

app.getPath("app","javascript"); returns  /C/Program Files (x86)/Adobe/Acrobat DC/Acrobat/JavaScripts so I added my script there

TOPICS
Acrobat SDK and JavaScript , Windows
3.1K
Translate
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 ,
Dec 05, 2018 Dec 05, 2018

Do you use the correct syntax for the path?

Translate
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 ,
Dec 05, 2018 Dec 05, 2018

I use :

var iconPath = "C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Javascripts\bcs.jpg";

var myDoc = app.newDoc();

myDoc.importIcon("bcsIcon", iconPath, 0);

When I copypaste it into the file browser, it opens the icon correctly so I guess it works

Translate
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 ,
Dec 05, 2018 Dec 05, 2018

Look at try67's first comment about the format of the path. You are using Windows syntax for the path, which will not work in an Acrobat JavaScript. You need to use Adobe's device independent format.

Translate
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 ,
Dec 05, 2018 Dec 05, 2018

oh right ! thank you, it's corrected

And god damn this is complicated... i now have an error in

app.addToolButton({

cName: "BCSadd",

oIcon: oIcon,

cLabel: "Finish PR",

cEnable: "event.rc = (app.doc != null);",

cExec: "BCSadd();",

nPos: 0

});

The arrow is on nPos: 0 , but I guess it can be anywhere in the function.

Would it be possible that this fail because the function BCSadd defined after is not correctly called ? It is written under the script : Imgur: The magic of the Internet

Translate
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 ,
Dec 05, 2018 Dec 05, 2018

I think the issue is that you have a function named BCSadd as well a menu item with that name. Try changing one of them...

And yes, this is complicated stuff, which is why it's very important to read the documentation carefully and keep an eye on the small details and the error messages you're getting.

Translate
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 ,
Dec 05, 2018 Dec 05, 2018

PS. In the future, please post the error message as text, in full, not as an image.

Translate
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 ,
Dec 05, 2018 Dec 05, 2018

Does it work when you remove following line?

oIcon: oIcon,

Have your script worked under Windows 7?

Translate
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
LEGEND ,
Dec 05, 2018 Dec 05, 2018

And the error is?

Translate
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 ,
Dec 05, 2018 Dec 05, 2018

try67​ you were right, I tried changing the function's name and restarting everything, but I get :

main()

Exception in line 17 of function main<, script Folder-Level:App:config.js

GeneralError: Operation failed.

App.addToolButton:17:Console undefined:Exec

undefined

with the following code :

app.addToolButton({

cName: "BCSadd",

oIcon: oIcon,

cLabel: "Finish PR",

cEnable: "event.rc = (app.doc != null);",

cExec: "BCSaddFunction();",

nPos: 0

});

(I tried removing the Icon line but it still trigger the error)

So I guess this does not see the BCSaddFunction, but as you can see here : Imgur: The magic of the Internet   The function exists 😕 Do you have an idea ?

Translate
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 ,
Dec 05, 2018 Dec 05, 2018
LATEST

Try narrowing it down. Remove all other code except for the addToolButton command. Does it still not work?

This code worked fine for me:

app.addToolButton({

cName: "BCSadd",

cLabel: "Finish PR",

cEnable: "event.rc = (app.doc != null);",

cExec: "BCSaddFunction();",

nPos: 0

});

Edit: Fixed wrong method name...

Translate
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