How to remove a password in a pdf bank statement to read in DT without entering every time?

How to remove a password in a pdf bank statement to read in DT without entering every time? Password remains the same either id no or account number

Did you search the internet with “PDF remove password”?

Apple’s PDFKit provides a method to open a PDF with a password passed in as a parameter. It might be possible to copy a PDF opened that way to a new one that is not password-protected.

Since I don’t have a password-protected PDF, I can’t try it out or provide code to achieve that.

Id prefer if it was automated using a script or something

Again: Did you search the internet? That’s the right place for this question.

This is a legal place to remove passwords in PDFs if you have the rights to (and know the password):

I don’t know how to remove passwords in PDFs and it probably depends on the creator setting permissions to allow you to do it, or something like that.

When I need/want to do this, I simply “print” a new PDF without password.

This always works unless the creator of the PDF sets permissions to dis-allow “printing”.

If it fails printing, and I think the creator will respond to a request to remove the password, then I ask. If the creator is a corporate machine … no way, most likely.

Yea, probably can find things via internet that claim to do this sort of thing, but I avoid all that.

1 Like

Hi, thanks this is how i do it, but id like to automate the process or to tell DT to use this password to use on all pdf with this account number

Probably a way using Apple Script, Java Script, or Python … experiment. I’ve moved your post to the Automation group in case someone wants to write the code for you.

1 Like

I haven’t done it in a while, but I was able to remove passwords from some paystubs one company sent out. I knew the password and I did the removing in Acrobat. It did require saving as a new version so I ended up with two copies, protected and not. One was easy to refer to and the other just in case I needed it for some official reason (that never arose)
The quantity of those documents never rose above the threshold for figuring out an automation.

The only way I found is to export the PDF from Preview as JPG, open the JPG again in Preview and export as PDF. Maybe you can do this with an Automator folder action or something like that. The export of the PDF can go to the Inbox folder of DT.

Just a thought to handle this.

2 Likes

I propose a JXA script. It can be run in Script Editor (after having set the language selector to JavaScript) or with osascript -l JavaScript script.js.
Change the first three lines of the code to contain the paths of an encrypted PDF and the unencrypted version as well as the password.

As I said before, I can’t test this code because I don’t have encrypted PDFs.
Edit I found an encrypted PDF in my e-mail and run the script successfully on it.

ObjC.import('PDFKit');

(() => {
  // CHANGE the following three lines to point to the path of the encrypted PDF, the unencrypted PDF, and the password
  const encryptedPDF = '/Users/you/Documents/nameof.pdf';
  const pathToNewPDF = '/Users/you/Documents/nameofnew.pdf';
  const password = 'ThePassword';
  
  const oldPDF = $.PDFDocument.alloc.initWithURL($.NSURL.fileURLWithPath($(encryptedPDF)));
  const newPDF = $.PDFDocument.alloc.init;
  oldPDF.unlockWithPassword($(password));
  const pageCount = oldPDF.pageCount;
  for (let i = 0; i< pageCount; i++) {
    newPDF.insertPageAtIndex(oldPDF.pageAtIndex(i), i);
  }
  newPDF.writeToFile($(pathToNewPDF));
})()
4 Likes

Here’s how you can do it: How to Remove Password from PDF on Mac | appsntips

2 Likes

Welcome @rachit
Thanks for the link to the article.

1 Like

I suppose that it also depends on what PDF readers you use. Something like PDF Expert has an easy feature to edit passwords. If you have it or something similar, you could save the document into DT4, apply a key trigger to launch an AppleScript and make the document open PDF expert and automates the process of changing the password. When you go back to DT you’d just have the PDF without the password.

1 Like

As shown, you can just trigger a script from. Within DT. No need for another program.

If you are comfortable with the command line you can use this library. I installed it from Homebrew. You can run scripts off it pretty easily with terminal commands. I haven’t used this in years, but it was reliable.