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

app.newDoc NotAllowedError despite enhanced security settings

leingang
Registered: Aug 4 2011
Posts: 3
Answered

Hello,
 
The big picture is that I want to take a scanned pdf in "2-up" format and split each page into two so that I can read it in iBooks. The method I have chosen is to try to duplicate each scanned page side-by-side. Having done that, I can crop odd-numbered pages to the verso side and even-numbered pages to the recto side. If you have better ways to do this, stop me now and let me know!
 
I took the snippet I found here and installed it in ~/Library/Application Support/Adobe/Acrobat/10.0/JavaScript:
 

app.addMenuItem({
        cExec: "duplicate_all_pages();",
        cParent: "Edit",
        cName: "Duplicate all pages"
});
&nbsp;<br />
function duplicate_all_pages() {
        var r = this.getPageBox();
        var w = r[2] - r[0];
        var h = r[1] - r[3];
        var oldD = this;
        var newD = app.newDoc({ nWidth: w, nHeight: h });
        var path = oldD.path.replace(oldD.documentFileName,"");
        for(var p=oldD.numPages-1; p>=0; p--) {
                pageFile = path+"page_"+p+".pdf";
                oldD.extractPages({ cPath: pageFile, nStart: p });
                newD.insertPages({ cPath: pageFile, nPage: -1 });
                newD.insertPages({ cPath: pageFile, nPage: -1 });
                //File.delete(pageFile);
        }
        return true;
}

 
When I select the menu item I get this error:
 

NotAllowedError: Security settings prevent access to this property or method.
App.newDoc:21:Menu Duplicate all pages:Exec

 
I looked in Preferences > Security (Enhanced) and "Enable Enhanced Security" is checked. I added my script to the list of "privileged" locations and restarted, but I get the same error. I tried also adding the folder containing this script, and even unchecking "Enable Enhanced Security". But I still get the NotAllowed error.
 
Is there another setting I'm missing?

My Product Information:
Acrobat Pro 10.1, Macintosh
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
And exactly what is the path name for the file you are trying to create.

Form the Acrobat JS API Reference:

"Safe path

"Acrobat 6.0 introduced the concept of a safe path for JavaScript methods that write data to the local hard drive based on a path passed to it by one of its parameters.
A path cannot point to a system critical folder, for example a root, windows or system directory. A path is also subject to other unspecified tests.

"For many methods, the file name must have an extension appropriate to the type of data that is to be saved. Some methods may have a no-overwrite restriction. These additional restrictions are noted in the documentation.
Generally, when a path is judged to be not safe, a NotAllowedError exception is thrown (see Error object) and the method fails."

I expect you are trying to write to a root directory or some temporary file location.

I would add at 'try{}catch(e){}' code to trap the error on failure and display on the JS console some of the variables you are

George Kaiser

leingang
Registered: Aug 4 2011
Posts: 3
Thanks for helping out, George.

I did a try/catch block and confirmed that the error occurs at line 11 in the snippet above, "var newD = app.newDoc({ nWidth: w, nHeight: h })." I'm confused that you think it has to do with the path because that method doesn't refer to any path yet; it's just a new empty document.

The document I am testing this on is within a user-writeable directory within my home directory, and the value of path at the break (I rearranged the code snippet to calculate this before the newDoc) is that directory.

Your last sentence seems to be unfinished, but in any case I'm not exactly sure how to use the JavaScript console for debugging. How would I do that?
leingang
Registered: Aug 4 2011
Posts: 3
I think I found it: In the "JavaScript" preferences tab there is a checkbox "Enable menu items JavaScript execution privileges." Checking that box got the script to work!
Ciantic
Registered: Sep 23 2011
Posts: 1
Accepted Answer
Yes, the JavaScript -> Enable menu item ... checkbox must be checked.I created an alternative script that does not create new document, but edits the open documen in-place (does not save, you must save afterwards if you wish):
app.addMenuItem({cExec: "duplicatePages();",cParent: "Edit",cName: "Duplicate all pages"}); function duplicatePages() {var doc = this;var pages = this.numPages;for (var i = pages - 1; i >= 0; i--) {doc.insertPages({cPath: doc.path,nStart : i,nEnd : i,nPage : i});}}
For some reason this forum doesn't add newlines to my code-block, see my code in full at blogspot.