Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update password to password protected file #2

Open
atodhruv opened this issue Aug 23, 2024 · 3 comments
Open

Update password to password protected file #2

atodhruv opened this issue Aug 23, 2024 · 3 comments

Comments

@atodhruv
Copy link

I some PDFs , some of are password protected & some not. I want following task to perform

  • check if pdf is password protected then update with new password
  • Check PDFs is without password nothing to do.

Can you help me to do this.
IMP. is to update password of password protected PDF.

I used this method to set password

coherentpdf.toFileEncrypted(pdf, coherentpdf.aes256bitisofalse, [coherentpdf.noEdit], password, password, false, false, protected_file_path);

Thanks in advance.

@johnwhitington
Copy link
Collaborator

You can:

  1. Load each file with fromFile - pass a blank string for user password
  2. Check if it's encrypted with isEncrypted
  3. If it is, re-write it with toFileEncrypted

@atodhruv
Copy link
Author

atodhruv commented Aug 27, 2024

@johnwhitington Thanks for reply. I tried but, PDF id created with blank pages.

let pdf = await coherentpdf.fromFile(filePath, 'Admin@123');
if(coherentpdf.isEncrypted(pdf)){
let permissions = [coherentpdf.noEdit];
coherentpdf.toFileEncrypted(pdf, coherentpdf.aes256bitisofalse, permissions, "Demo@123", "Demo@123", false, false, newFilePath,);
}

@johnwhitington
Copy link
Collaborator

Can you make a standalone example for me to test? i.e

  • an input file
  • a JavaScript program I can run from node at the command line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants