We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.
I've spent quite a while looking for information on this and come up short:
Apparently there are security settings which interfere with just using the command (I've tried setting my Desktop and a specific PDF on the Desktop to be trusted without success).
Running the command:
in the console gets the error:
GeneralError: Operation failed.
I have. Several times.
It is out of date, and doesn't provide the specific details which I have asked after --- please either provide these specifics, or provide a link to up-to-date documentation which has them.
This aricle covers ths details:
This article shows how to create and use trusted functions:
This article explains trust and privilege in Acrobat:
For anyone who comes here via a search:
So I placed what I hope to be appropriate code into a globs.js file in the aforementioned directory:
and yet I am placing my code in an action, yet I still get an error:
RaiseError: The file may be read-only, or another user may have it open. Please save the document with a different name or in a different folder.
===> The file may be read-only, or another user may have it open. Please save the document with a different name or in a different folder.
which I assume is a security issue (when I searched that is what was indicated). If that's not it, I'd appreciate a pointer to what the actual difficulty is.
For the sake of compleatness' the code I have in the action is:
About this Action Script. The path build has an issue with this code
These lines will create a path that looks like this
Change it to this
if the error message is telling you that the "Trusted_MyDocSave" is not defined, then it's not defined.
One possible issue is that Acrobat was not shutdown all the way. Please exit Acrobat and check the task manager to make sure it's not running. Then restart Acrobat and check to console window to see if any errors are reported.
I've quit Acrobat, rebooted, and re-tried, but still getting the same error messages, either undefined function, or not being allowed to save.
Why isn't there a single page which documents how to achieve what I'd think would be a pretty straight-forward (suitable as an example) task?
There is a documents that does show how to do this, and you've already read it. The problem is that you are doing something wrong. We have to figure out what that is.
There is only one single issue here. Which is, "why isn't your folder level function getting defined?" This often happens because there is something else in the same file that is failing. Is there other code in this "Globs.js" file?
Did you check the console window after restarting Acrobat for any startup errors?
Something you can try to make sure the function works, is to define it in the Console. And then see if there is a problem with your other scripts using it.
On another note, you may want to add a path argument to the function, so you can control the save location of the extracted pages.
Turns out there were two issues.
First off, the code copied from that web page was wrong, and the corrected code which you provided:
// Put path back together and save
fixed this so that it now saves. Thank you.
The remaining difficulty is that it saves the wrong PDF with the new name, the original one, not the extracted one.
which I was hoping was caused by a mis-placed parentheses, but shifting that didn't work. The solution of course is to replace this. with d.
I also struggled to find how to create a simple menu that allows to save the current document on the desktop. Finally I did it!
Here is the code:
// The trusted function that does the Save As
vPath = "/c/Users/[User Name]/Desktop/" + oDoc.documentFileName
var Trusted_SaveOnDesktop = app.trustedFunction(SaveOnDesktop);
// The creation of the menu
cName: "Save on Desktop",
- JS is case sensitive oDoc.SaveAs() does not work, it's oDoc.saveAs()
- I got confused with oDoc thinking it could be the name as the current document, but it's the object. Thus the need to create the vPath variable for the name of the document.
- I used the two-step variant for the trusted function, because when I searched the internet it was more complicated for me to understand examples where the two steps were merged. So you will see in my code that the creation of the variable Trusted_SaveOnDesktop comes as a 2nd step. You can merge the two together as shown in other examples below.
- I used alerts to know what was the content of the variables (that's how I discoverd that oDoc was the object).
Super basic, I'm sure! :-)) But quite happy it finally worked at the end of the day. I hope it will be useful for beginners like me!
I read your post with interest, but couldn't figure out how I can solve my problem.
Can I ask you how can I solve my problem?
I opened the console with ctrl + j.
I tried this formula:
var oMyDoc = this.extractPages (5)
var cMyPath = oMyDoc.saveAs ("/C/Users/Tabene/Documents/QUESTION.pdf");
app.execMenuItem ("Save", oMyDoc, cMyPath);
If I put the formula in a button it doesn't work.
I've read the instructions on this page, https://www.pdfscripting.com/public/Using-Trusted-Functions.cfm, but I can't build a function that works.
Why, exactly, can't you build a function that works? The instructions are good - so long as you don't try to skip anything - so we need complete details of what you do, and what the console says, and what happens.
The "app.execMenuItem " line is redundant. Remove it.
Trusted functions are a somewhat advanced scripting topic. So, you have to pay attention to the details and be careful about how you write the code, and where that code is placed.
Please post your folder level code in full.
myPropagatorFunction = app.trustPropagatorFunction(function(oMyDoc,cMyPath)
PDF ButtonCode under button that is executed on Mouse up click:
var oMyDoc = this.extractPages (5)
var cMyPath = oMyDoc.saveAs("/C/Users/Tabene/Documents/QUESTION.pdf");
I press the button and in the console it appears written
NotAllowedError: Security settings do not allow access to this property or method.
Doc.saveAs: 2: Field Button2: Mouse Down
You've done half the job. You defined a privileged routine. It's not actually right, but it's the right idea. However, on your button, you contine to call oMyDoc.saveAs. This is just the standard saveAs routine; it failed before you made a privileged routine, and it keeps failing.
I think you probably have the right instructions, but need to follow them more closely.
The key part to work on first is that you have to replace the oMyDoc.saveAs call by calling the privileged routine. The code in your document will never contain oMyDoc.saveAs
You've sort-of have the idea.
This article provides the exact code you need: