I am trying to add password security to my pdf’s, using applescript and the “do script” method of using javascript, I am not literate in javascript at all and would appreciate some help please in trying to achieve this.
I do not need certificates etc, basically all I need is to use basic password security to protect my pdf’s.
The below is what I am trying to achieve.
add a password to restrict editing and printing (hard coded)
allow printing low: quality
changing document: none
document assembly: none
content copying and extraction: none
content copying and extraction for accessibility: none
commenting: none
filling of form fields: none
signing: none
creation of template pages: none
save as, at current document location
Adobe Acrobat 8.1.3
Mac OSX 10.4.11
Mac OSX 10.5.7
I have found a work around for now, not elegant but it works, using GUI scripting :rolleyes:, until I can come across a better solution to do what I am after.
I am using Acrobats Security Policy set up an initiating it via GUI scripting where applicable in my code.
Well now that you have gone the way of using policies you may well be able to use JavaScript over GUI.
This should get you a list (array) of available policies:
var policyArray = security.getSecurityPolicies();
This will go through the array to find match by name:
for (var i = 0; i < policyArray.length; i++) {
if (policyArray[i].name == ‘Marks Password’) {
var myPolicy = policyArray[i]
}
}
This should apply given policy:
this.encryptUsingPolicy( myPolicy );
Here is an example for you to test:
set Default_Path to (path to desktop as Unicode text)
set PDF_Security to "var policyArray = security.getSecurityPolicies(); for (var i = 0; i < policyArray.length; i++) {if (policyArray[i].name == 'Marks Password') { var myPolicy = policyArray[i]}} this.encryptUsingPolicy( myPolicy );"
tell application "Adobe Acrobat 7.0 Professional"
activate
tell active doc
set File_Name to name
do script PDF_Security
if modified is true then
save to file (Default_Path & File_Name) -- Save as required. For Certified Document
close
end if
end tell
end tell
Just change the name ‘Marks Password’ inside of the single quotes then it requires no escaping.
Your code runs like a dream (thankyou) on OSX 10.4.11 PPC Acrobat 8.1.3 Applescript 1.10.7, but fails on OSX 10.5.7 Intel Acrobat 8.1.3 Applescript 2.0.1, at the “do script” portion of the code.
I feel that this issue lies around the same area that pandrake has pointed out in my other post http://macscripter.net/viewtopic.php?id=29440 that deals with do script and Unicode text.
Like Pandrake has said “There’s gotta be a way to coerce AppleScript 2.0.1 strings into 8-bit text, since it appears that’s what Acrobat 8 wants for it’s ‘do script’ action.”, until then I/we area at a dead end.
Budgie, I have followed the posts made in your other thread. And last night took home my sample scripts as I have a Leopard Intel Imac there (everything in work is non-intel and Tiger) I normally just use this for JavaScript learning as AppleScript does give me some unpredictable results when running CS2 apps on this box. I tested just about everything I could thing of and nothing worked at all!!! (Not even any errors kicked back). You will notice on Tiger in Script Editor that the JavaScript passes back a resulting security object where as in Leopard it does nothing the modified of document is false and it can be closed without saving. I tested many JS strings that all work in Acrobat’s console but found no solution. Even got the new ASLG for AS2 and found nothing in that of any help. Both of these can be done via ‘Batch Processing’ and this may be your only route for the time being. Sorry to be of no help.
Im at work now and did not have the time last night to check this out. You could give these a quick run on a Leopard box and if they all work then it’s a problem with Adobe’s Acrobat ‘do script’ (in V7 & V8 at least) if none run then its more likely to be down to AppleScript’s Unicode text.
set Foo to "Test_String('Some Text to test.'); function Test_String( foo ) {alert( foo );}"
tell application "Adobe InDesign CS2"
activate
do script Foo language javascript
end tell
set Foo to "Test_String('Some Text to test.'); function Test_String( foo ) {alert( foo );}"
tell application "Adobe Photoshop CS2"
activate
do javascript Foo
end tell
set Foo to "Test_String('Some Text to test.'); function Test_String( foo ) {alert( foo );}"
tell application "Adobe Illustrator"
activate
do javascript Foo
end tell
“Sorry to be of no help.” how incorrect you are, you as pandrake have been of enormous help to me and im sure many others.
Your code tested this morning on OSX10.5.7 Intel, Adobe CS3-Photoshop, Illustrator and Indesign, Applescript 2.0.1all ran perfectly, so based on these findings “it’s a problem with Adobe’s Acrobat ‘do script’ (in V7 & V8 at least)”, so where to now?
forgot -the test on Acrobat 8.1.3 came back as you predicted.
Adobe Acrobat Professional got an error: “Test_String(‘Some Text to test.’); function Test_String( foo ) {alert( foo );}” doesn’t understand the do script message.