These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

NotAllowedError - executing extractPages through the Menu

JBallant
Registered: Oct 13 2009
Posts: 6

Hello,

I have gone through the JS developers guide but I cannot figure out how to execute an extractPages method without getting the "NotAllowedError" for it.

I am using Acrobat Standard 7.0 and I wanted to try to enable privileges option named "Enable Menu Items JavaScript Execution Privileges" in the Preferences menu but it doesn't seem to be there, either in the "General" menu or the "JavaScript" menu.

I also tried to see if I could use app.trustedFunction but I cannot find the config.js file. It does not appear to exist.

Will this simply not work on Standard or am I missing something?

My Product Information:
Acrobat Standard 7.0, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
The security restrictions in version 7 were much less strict compared to later versions, so the problem is probably your code. Post it here and maybe someone will spot the problem.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

JBallant
Registered: Oct 13 2009
Posts: 6
Okay, I can post the code. I am pretty new to JavaScript, but I thought I would be able to get this little bit of code working if I stuck fairly closely to the Developers guide and the JS reference. I, perhaps wrongly, assumed I would only get this error because of something to do with privileged context.

var theWord, numWords, startPage, endPage, filename;startPage = 1;filename = "Test1"; for (var i = 0; i < this.numPages; i++ ){numWords = this.getPageNumWords(i);for (var j = 0; j < numWords; j++){theWord = this.getPageNthWord(i, j) //if ( theWord = "Trans" ) 	//if the word is "Trans" {endPage = ithis.extractPages({nStart: startPage,nEnd: i,cPath: "/C/Test/"+filename+"_" + i +".pdf"});}}}
try67
Expert
Registered: Oct 30 2008
Posts: 2398
First of all, you're using the wrong operator in this line:
if ( theWord = "Trans" )
It should be:
if ( theWord == "Trans" )

Also, try using a different path as it's possible Acrobat considers c:\test\ to be "unsafe" for some reason.
Another thing: You set startPage to be 1. Shouldn't it be 0?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

JBallant
Registered: Oct 13 2009
Posts: 6
Thanks for the reply,

You're completely right about the "==" and the start page, but neither of those seemed to cause the error. I also tried several different paths, including to external flash memory, and to a folder in My Documents, I still get this message:

"NotAllowedError: Security settings prevent access to this property or method.
Global.extractPages:17:Bookmark undefined:Mouse Up"

I've just had the code attached to a bookmark, could that be causing it? I've tried to have it execute as a Document Action Script when the event "Document Did Save" occurs. Should I put it as an option in the menu? I avoided that because there doesn't seem to be a "Enable Menu Items JavaScript Execution Privileges" option and the file config.js doesn't seem to exist to add the menu item.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
You didn't mention that you were launching this from a bookmark... In that case, you probably do need a privileged environment.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
As stated in the JavaScript Reference, "doc.extractPages()" requires priviledge, which means it can't be called directly from a bookmark script. You can do a couple of things to solve the issue.

1. Create a folder level trusted function that runs your code. See this Article:
http://www.acrobatusers.com/tutorials/2008/10/using_trusted_functions

2. Place your code in a Menu item using the "app.addMenuItem()" function, Enable Menu item priviledge from the preferences, and then call the menu item, "app.execMenuItem()" from your bookmark.

Note that both of these solutions require that you make changes on your system, so the solution/document will only work on a system where these changes are made. That's the deal with trust, the user has to specifically allow a secure function to run on thier system, and with Acrobat 9.2 it's gotten even more restricted so if you are going to be using priviledged functions you really need to understand the security restrictions.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

JBallant
Registered: Oct 13 2009
Posts: 6
Thanks so much for the info, the tutorials were very helpful. I got confused because I thought config.js should already exist, and the option to enable menu item privilege isn't there for me.

Now, of course, my code won't work because the "this" reference is undefined in a folder level trusted function.

I think I may be able to figure out someway to deal with this, but does anyone know a good way to pass the "doc" object representing the pdf I want to use the extractPages method on as a parameter to the folder level trusted function?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes, just pass it in as an argument to the trusted function. If the function is being called from a document script the pass in "this".

For Example, If your function is:
var myTrusted = app.trustedFunction(function(oDoc){app.beginPriv();....

oDoc.extractPages(...);...

app.endPriv();});

Then to use this function in a bookmark script
    myTrusted(this);
That's it

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

JBallant
Registered: Oct 13 2009
Posts: 6
YES. It works. Wonderful.

Thank you so much!