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" }); <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?
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