Open mac5yver opened 2 months ago
same problem here. encrypted PDF using pymupdf cannot be saved, getting the same error message: "The document could not be saved. There was a problem reading this document (21)."
The file could be opened, and the Document Restriction settings are all correct based on the encryption parameters used. The errors occurs whenever I tried to save the file after adding a comment to the file. I also tried just to save the PDF using Acrobat Pro, same error message.
test files were created using MS Word. Input file: testfile.pdf Encrypted file: testfile_encrypted.pdf
Description of the bug
All attempts at saving a pdf with encryption and an owner_pw result in a PDF that will open in Acrobat Pro (2024.002.20964) on macOS, but after adding, for example, a comment, Acrobat cannot save the document. Acrobat throws the following error: "The document could not be saved. Bad parameter."
How to reproduce the bug
Example file: protected.pdf
Created with this code:
I've tried many variations of garbage collection, compression, and cleaning. All PDFs I create open in Acrobat Pro, but they will not save. Acrobat offers to Save As, but then fails with this error: "The document could not be saved. There was a problem reading this document (21)."
Removing the encryption, owner_pw, and permissions arguments from the save function results in a PDF that works fine in Acrobat, but is not protected.
Of note, the PDFs open and save again just fine in PDF X-Change on Windows.
Any help is much appreciated.
PyMuPDF version
1.24.9
Operating system
MacOS
Python version
3.12