• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Script to open password protected pdf into Illustrator with a known password

Participant ,
May 18, 2023 May 18, 2023

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.

TOPICS
Scripting

Views

708

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , May 18, 2023 May 18, 2023

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.

Votes

Translate

Translate
Participant , May 18, 2023 May 18, 2023

Got this working by creating an Applescript app with keystrokes and then calling from the .jsx file.

Thanks for the input, much appreciated.

Votes

Translate

Translate
Community Expert ,
May 18, 2023 May 18, 2023

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 18, 2023 May 18, 2023

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 18, 2023 May 18, 2023

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 18, 2023 May 18, 2023

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 18, 2023 May 18, 2023

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied

Got you, ok, that leads me down the right path then. thanks for your input, Carlos.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 18, 2023 May 18, 2023

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 19, 2023 May 19, 2023

Copy link to clipboard

Copied

awesome! do you mind posting your solution for posterity?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 22, 2023 May 22, 2023

Copy link to clipboard

Copied

LATEST

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.")
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines