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

PDFs saved with encryption cannot be saved in Acrobat Pro with "Bad parameter" error #3762

Open
mac5yver opened this issue Aug 8, 2024 · 1 comment

Comments

@mac5yver
Copy link

mac5yver commented Aug 8, 2024

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:

def protect_pdf():
    perm = int(
        pymupdf.PDF_PERM_ACCESSIBILITY
        | pymupdf.PDF_PERM_PRINT
        | pymupdf.PDF_PERM_PRINT_HQ
        | pymupdf.PDF_PERM_ANNOTATE
        | pymupdf.PDF_PERM_ASSEMBLE
        | pymupdf.PDF_PERM_COPY
        | pymupdf.PDF_PERM_FORM
    )
    doc1 = pymupdf.open()
    doc1.new_page()
    doc1.save(
        "protected.pdf",
        encryption=pymupdf.PDF_ENCRYPT_AES_256,
        owner_pw="owner",
        permissions=perm,
        garbage=4,
        deflate=True,
        clean=True,
    )
    doc1.close()

protect_pdf()

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

@GrandmaMeemaw
Copy link

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

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