You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There seem to be some confusion between User Access Permissions and Document [Security] Restrictions, when handling permissions. (Or at least I am confused, because it looks like you are mixing up the two.)
User Access Permissions is used for setting permissions on encrypted files requiring a password.
Document [Security] Restrictions can be set on any PDF file (without encryption)
There is also an ambiguous DeprecationWarning that tell you to use another thing, and then doesn't work.
Looking at some PDF document you can have the Document [Security] Restrictions as shown in Adobe Acrobat, without any Encryption.
Here's how my PDF looks.
(Sorry, I cannot share it as it belongs to a company.)
So if I have a non-encrypted PDF with the following restrictions:
EXTRACT_TEXT_AND_GRAPHICS
ASSEMBLE_DOC
(512 and 1024, respectively)
The question is:
How do I read these from the PDF?
How do I change them in the same PDF?
Environment
Which environment were you using when you encountered the problem?
importpypdffrompypdfimportPdfReader, PdfWriterfrompypdf.constantsimportUserAccessPermissionsIFILE='some.pdf'reader=PdfReader(IFILE)
reader.decode_permissions(UserAccessPermissions.all())
# ...# <stdin>:1: DeprecationWarning: decode_permissions is deprecated and will be removed in pypdf 5.0.0. Use user_access_permissions instead.reader.user_access_permissions(UserAccessPermissions.all())
# TypeError: 'NoneType' object is not callable
The text was updated successfully, but these errors were encountered:
It seems like you are mixing up something: A PDF file can have a user password and an owner password. The user password is required each time you open the file. An owner password is used to restrict the permissions a regular user (without specifying the owner password) should be allowed to do.
You are correct that decode_permissions has been deprecated as this rather is a property on the document. Nevertheless, you are using both functionality wrong (see #2389 (comment) as well): You either want
reader.decode_permissions(reader._encryption.P) (deprecated) or
reader.user_access_permissions (flags instance) or reader.user_access_permissions.to_dict() (dictionary similar to the one from decode_permissions().
Alternatively, you might pass any set of permission flag value into UserAccessPermissions() to get a verbose representation of it.
To change the permissions, use PdfWriter.encrypt() with the appropriate parameters.
There seem to be some confusion between
User Access Permissions
andDocument [Security] Restrictions
, when handling permissions. (Or at least I am confused, because it looks like you are mixing up the two.)User Access Permissions
is used for setting permissions on encrypted files requiring a password.Document [Security] Restrictions
can be set on any PDF file (without encryption)There is also an ambiguous
DeprecationWarning
that tell you to use another thing, and then doesn't work.Looking at some PDF document you can have the
Document [Security] Restrictions
as shown in Adobe Acrobat, without any Encryption.Here's how my PDF looks.
(Sorry, I cannot share it as it belongs to a company.)
So if I have a non-encrypted PDF with the following restrictions:
(512 and 1024, respectively)
The question is:
Environment
Which environment were you using when you encountered the problem?
Code + PDF
This is a REPL example that shows the issue:
The text was updated successfully, but these errors were encountered: