-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
PyPDF2 can't decrypt PDF files with Acrobat 6.0 or higher password security compatibility #378
Comments
Possible duplicate #53? |
I am not sure why but #53 seems to have been closed. This problem, however, still continues. |
@apaksoy It seems as if no permanent fix has been made for this, but one of the solutions ( which suggests the use of the command-line utility qpdf ), worked fine for me. Could you try the same for your failed cases? |
I will be away for about a week. Will try and post here when I return. |
hello everybody , any news about this issue ? |
my friend add this line to your code inputpdf.decrypt(''). from PyPDF2 import PdfReader, PdfWriter
reader = PdfReader(full_file_name)
reader.decrypt('')
for index,temp_tracking_number in enumerate(self.additional_tracking_codes):
writer = PdfWriter()
writer.add_page(reader.pages[index])
with open(str(temp_tracking_number) + ".pdf", "wb") as fh:
writer.write(fh) |
@ganeshtata Thank you for the suggestion but qpdf but does not work for me because I am looking for a solution within PyPDF2. @maxiplux Thx but I am not exactly sure what you are suggesting as new. As I mentioned in my original post, the code I posted already works for PDF files with Acrobat 5.0 password security compatibility (or PDF files created via PyPDF2). I did not paste the part of the code that copies the pages to a new PDF file and writes it to disk in the original post because it makes no difference if a file can not be decrypted at the first place. Can you pls also properly mark your code, i.e. use the grave accent ` in triple form, when you include code in your messages here? |
@apaksoy The problem is, PyPDF2 doesn't support certain encryption algorithms, yet. This #226 indicates that decryption for some encryption algorithms is yet to be implemented. I know you are looking for a solution within PyPDF2, but in case you ever plan to venture out for a similar library, you can take a look at pikepdf, a python library that uses qpdf. |
… '') using PyPDF2 py-pdf/pypdf#378 This is a workaround using external executable: qpdf
… '') using PyPDF2 py-pdf/pypdf#378 This is a workaround using external executable: qpdf
any update on this ? |
I would also like updates regarding this issue |
Work around for me was using PyMuPDF. Depending on the use case I either used it directly or saved the file again and the reopend it with the regular framework. |
@c0nb4 since PyMuPDF is based on MuPDF its under AGPL license and if you use it inside your project that you are distributing... you have to distibute as AGPL aswell or buy a license. |
PikePDF can be used to open encrypted files (Created by Acrobat 6.0). Below is the simple code:
|
Thanks bro, it worked. |
Mine wasn't password-protected so removing the second argument worked. [Edit] |
Might be fixed with #749 Running the script from above:
|
PyPDF2==2.4.0 with #1015 now supports R=6 decryption 🎉 |
Running the example from above, I get:
|
@exiledkingcc The |
it failed at |
It seems to be save to ignore the /Perms entry: Qpdf ignores it: https://github.com/qpdf/qpdf/blob/main/libqpdf/QPDF_encryption.cc#L1064 pdfbox ignores it: https://github.com/apache/pdfbox/blob/dc1a75027d5bebf95a3330f6298a533e78e0b99e/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java#L311 Closes #378
Hi,
I get the "NotImplementedError: only algorithm code 1 and 2 are supported" error when I try the .decrypt() method on a PDF file saved with password security compatible with Acrobat 6.0 or higher.
Below is the code I used for decryption trials. Also below are the links to four different versions of the same file saved with the specified compatibilities in their filenames as examples. All have the same password 'password' (without the quotes).
I tried this with other PDF files and got the same result. That is, no error when saved with Acrobat 5.0 password security compatibility and always an error when saved with Acrobat 6.0 or higher password security compatibility.
I used Adobe Acrobat Pro X to save a file with different password security compatibilities. I have PyPDF2 1.26.0 installed on Python 3.6.3 on mac OS 10.13.1. Thank you.
test_file_acrobat_5.pdf
test_file_acrobat_6.pdf
test_file_acrobat_7.pdf
test_file_acrobat_10.pdf
The text was updated successfully, but these errors were encountered: