Copy link to clipboard
Copied
I have a script that outputs a password protected pdf file, so therefore know the password. Is there a way to use this known password to reopen the pdf file via a script, meaning no users have access to the doc other than via the scripting?
Thanks in advance.
there's no scripting API to open password protected pdf files but there's hope, once the password window comes up, in theory you could "send keys" to it. It's like simulating the user typing the password.
Got this working by creating an Applescript app with keystrokes and then calling from the .jsx file.
Thanks for the input, much appreciated.
Copy link to clipboard
Copied
Do a web search for opening password protected PDFs.
It will take you about 1 minute to open the PDF. And this of course applies to everyone who can do a web search.
Copy link to clipboard
Copied
Thanks for the quick reply. I have been searching for my specific answer but most answers I found are how to get around not having the password available. As I have the password I was wondering if there was a correct syntax to use to open the file as I cannot seem to find anything.
Copy link to clipboard
Copied
PDF password protection is not a protection. The whole point is that everyone who is able to do a web search also has access to your file.
Copy link to clipboard
Copied
Ok, thanks. Password protecting the file is sufficient for what I need, just to stop others opening it and changing it by accident rather than full on security.
I take it there is no Extendscript syntax for opening using the password then.
Copy link to clipboard
Copied
there's no scripting API to open password protected pdf files but there's hope, once the password window comes up, in theory you could "send keys" to it. It's like simulating the user typing the password.
Copy link to clipboard
Copied
Got you, ok, that leads me down the right path then. thanks for your input, Carlos.
Copy link to clipboard
Copied
Got this working by creating an Applescript app with keystrokes and then calling from the .jsx file.
Thanks for the input, much appreciated.
Copy link to clipboard
Copied
awesome! do you mind posting your solution for posterity?
Copy link to clipboard
Copied
Sure thing. This is how I went about it:
1. save a file out with 'requireDocumentPassword' set to true and apply the password 'Password123' to the file;
var reqName = "Test_Lock";
saveAspdfFile(reqName);
function saveAspdfFile(reqName) {
var doc = app.activeDocument;
var input = new File("~/Desktop");
var newFile = File(input + "/" + reqName + ".pdf");
var pdfFile = new File(input + "/" + reqName);
var pdfOps = new PDFSaveOptions();
pdfOps.compatibility = PDFCompatibility.ACROBAT5;
pdfOps.preserveEditability = true;
pdfOps.preset = "[Illustrator Default]";
pdfOps.documentPassword = "Password123";
pdfOps.requireDocumentPassword = true;
doc.saveAs(pdfFile, pdfOps);
doc.close();
}
2. Created an 'Application' within 'Automater' containg the following AppleScript code (AppleScript is not my forte so apologies if anyone finds error in it), the app is called 'AddPasswordApp';
tell application "/Applications/Adobe Illustrator 2022/Adobe Illustrator.app"
activate
tell application "System Events"
keystroke "Password123"
keystroke return
end tell
end tell
3. Called the above app to run in the 'Open' script;
var lockedFile = new File("~/Desktop/Test_Lock.pdf");
var address1 = lockedFile;
var file1 = File(address1);
var appleScript = new File("~/Desktop/AddPasswordApp.app");
if (appleScript.exists) {
appleScript.execute();
file1 = open(file1);
} else {
alert("WARNING:\nRequired AppleScript not available.")
}