Skip to main content
Participating Frequently
December 4, 2018
Question

How to execute a Trusted script on the open document ?

  • December 4, 2018
  • 20 replies
  • 3099 views

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

This topic has been closed for replies.

20 replies

Legend
December 5, 2018

Illegal character is sometimes a coding error but more often it's an error in how the script is saved. For example, did you save it as a Word document? What encoding did you select when saving the file - if you're not sure, what did you edit it with (Notepad is recommended)?

Legend
December 5, 2018

Acrobat (we prefer not to call it Adobe) doesn't remember anything. If it is finding this script AFTER you have definitely quit and restarted Acrobat it is because you have left it somewhere and it's still being picked up. Perhaps in a document level script, and perhaps in startup scripts.

When dealing with errors it's best to take them from the top, rather than pick out interesting ones that seem easier to fix. Quite often, the first error will be causing the others.

So, the first error seems to be this

SyntaxError: illegal character

1:Folder-Level:App:config.jsException in line 23 of function top_level, script Document-Level:AddBSC

But please quit Acrobat and check. Check the JavaScript console BEFORE opening any files AND before running your action, so you can see exactly which errors relate to the startup script. Then open the document and see which errors, if any, now appear. Finally, run the action. You now know which part is triggering which error.

Not allowed errors are sometimes overcome by using a trusted script (Just putting a script in the startup folder does NOT however make it trusted unless you code it that way.) You can check the documentation of the method used to see what is needed. Have you done this?

Participating Frequently
December 5, 2018

Ah nice catch ! I changed the PDF used for the test, and AddBSC don't show anymore, so i guess I added it in the PDF somehow.

Now when I execute the script, I have this :

SyntaxError: illegal character

1:Folder-Level:App:config.js

SyntaxError: illegal character

1:Folder-Level:App:config.jsException in line 1 of function top_level, script Batch:Exec

So the script is correctly loaded, which is nice. Now I just need to debug it line by line and correct all errors. Thank you for your help

Participating Frequently
December 5, 2018

I think it is not correctly installed.

What I tried to do :

- Create an Action with the Action Wizard to execute a javascript

- In the javascript, I only added main()

- open my document, Execute the javascript.

I have those errors in the debugger :

SyntaxError: illegal character

1:Folder-Level:App:config.jsException in line 23 of function top_level, script Document-Level:AddBSC

NotAllowedError: Security settings prevent access to this property or method.

App.trustedFunction:23:Document-Level:AddBSC

Exception in line 1 of function top_level, script Batch:Exec

ReferenceError: main is not defined

1:Batch:ExecException in line 1 of function top_level, script Batch:Exec

ReferenceError: main is not defined

1:Batch:ExecException in line 1 of function top_level, script Batch:Exec

AddBSC is a function I defined before that I deleted, but I guess Adobe remember it somehow ?

And main is not defined.

@TestScreenName, I'm doing it this way because when I try to simply execute the script from the open document, I have a NotAllowedError, which from what I saw online requires the script to be added in the trusted folder.

Bernd Alheit
Community Expert
Community Expert
December 5, 2018

Clear the debugger output and restart Adobe Acrobat (without open a document). What messages did you get?

Legend
December 5, 2018

You would just call main() in any JavaScript context. Such as from the console, but more usually from an embedded JavaScript on a button or other form field.

Do you understand why trusted functions are needed? If not, this is all going to seem unnecessarily complicated.

Bernd Alheit
Community Expert
Community Expert
December 5, 2018

The function main adds only the tool button.

Participating Frequently
December 5, 2018
The script may define functions, including trusted functions. You can call these in any context

Ok, so I think I correctly defined a method "main" in my function : var main = app.trustedFunction(function () { ...

So if I understand you well, scripts placed in those folders will actually simply be read at startup and Adobe will remember the function defined there, right ? Now how do I call this function ? By simply writing main ?

try67
Community Expert
Community Expert
December 5, 2018

To test if your folder-level script is installed correctly add the following line at the top of it (OUTSIDE any function definition):

app.alert("Hi!");

When you open the application an alert message with that text should appear. If it doesn't, the script is not installed properly.

Legend
December 5, 2018

There is nothing in Acrobat that shows you these defined scripts. I don't really understand what you are looking for.

The script is executed at startup. Once and once only. You cannot execute it again.

The script may define functions, including trusted functions. You can call these in any context.

Participating Frequently
December 5, 2018

@test I added the script in the folder. I thinks that is what you mean by being defined. Then, I want to use that script. I don't see anything in Adobe that would let me access, call, write... that script in an action wizard or anywhere else.

@Bernd Where should it create a tool button ? I'm in the tool menu and there are only the default actions

Bernd Alheit
Community Expert
Community Expert
December 5, 2018

The tool button is at Tools > Add-on Tools. The label is "Finish PR".

Participating Frequently
December 5, 2018

Hello,

thank you both for your answer try67​ Joel_Geraci, but the problem at the moment is simply to be able to play the code. The script does not show anywhere in Adobe.

Legend
December 5, 2018

You say the script "does not show anywhere in Adobe". But scripts are just defined, not shown. What exactly do you mean by "shown"?

try67
Community Expert
Community Expert
December 4, 2018

Either folder will work, but there's an error in your code. You did not specify the iconPath variable correctly.

The correct syntax is;

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

And the file doesn't have to be located in the trusted folder, by the way. It can be anywhere.

To call the first function use this command:

main();

Joel Geraci
Community Expert
Community Expert
December 4, 2018

One of the first things the script does is try to read a file from...

C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Javascripts\bcs.jpg

... but there's no error checking so it just fails if not found.

Did you migrate that file as well when you updated your machine?