Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions docs/document.rst
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ For details on **embedded files** refer to Appendix 3.
:attr:`Document.needs_pass` require password to access data?
:attr:`Document.outline` first `Outline` item
:attr:`Document.page_count` number of pages
:attr:`Document.permissions` permissions to access the document
:attr:`Document.permissions` permissions to access the document with the user password.
:attr:`Document.pagemode` PDF PageMode value
:attr:`Document.pagelayout` PDF PageLayout value
:attr:`Document.version_count` PDF count of versions
Expand Down Expand Up @@ -807,13 +807,28 @@ For details on **embedded files** refer to Appendix 3.
:returns: a positive value if successful, zero otherwise (the string does not match either password). If positive, the indicator :attr:`Document.is_encrypted` is set to ``False``. **Positive** return codes carry the following information detail:

* 1 => authenticated, but the PDF has neither owner nor user passwords.
`needs_pass` will be False, and authentication was not required.
* 2 => authenticated with the **user** password.
* 4 => authenticated with the **owner** password.
* 6 => authenticated and both passwords are equal -- probably a rare situation.

.. note::

The document may be protected by an owner, but **not** by a user password. Detect this situation via `doc.authenticate("") == 2`. This allows opening and reading the document without authentication, but, depending on the :attr:`Document.permissions` value, other actions may be prohibited. PyMuPDF (like MuPDF) in this case **ignores those restrictions**. So, -- in contrast to any PDF viewers -- you can for example extract text and add or modify content, even if the respective permission flags `PDF_PERM_COPY`, `PDF_PERM_MODIFY`, `PDF_PERM_ANNOTATE`, etc. are set off! It is your responsibility building a legally compliant application where applicable.
The document may be protected by an owner, but **not** by a user password.

Detect this situation via `doc.authenticate("") == 2`.

This allows opening and reading the document without authentication but,
depending on the :attr:`Document.permissions` value, other actions may be prohibited.

However PyMuPDF (like MuPDF) in this case **ignores those restrictions**.
So, -- in contrast to any PDF viewers
-- you can for example extract text and add or modify content,
even if the respective user password permission flags
`PDF_PERM_COPY`, `PDF_PERM_MODIFY`, `PDF_PERM_ANNOTATE`,
etc. are set off!

It is your responsibility building a legally compliant application where applicable.

.. method:: get_page_numbers(label, only_one=False)

Expand Down Expand Up @@ -1682,7 +1697,7 @@ For details on **embedded files** refer to Appendix 3.

:arg bool appearance: (re)create the appearance streams of annotations and widgets while saving.

:arg int permissions: *(new in v1.16.0)* Set the desired permission levels. See :ref:`PermissionCodes` for possible values. Default is granting all.
:arg int permissions: *(new in v1.16.0)* Set the desired permission levels for the ``user`` password. See :ref:`PermissionCodes` for possible values. Default is granting all.

:arg int encryption: *(new in v1.16.0)* set the desired encryption method. See :ref:`EncryptionMethods` for possible values.

Expand Down Expand Up @@ -2544,12 +2559,25 @@ For details on **embedded files** refer to Appendix 3.

.. attribute:: permissions

* Changed in v1.16.0: This is now an integer comprised of bit indicators. Was a dictionary previously.
Contains the permissions to access the document after authenticating with the user password.
This is an integer containing bool values in respective bit positions.

Contains the permissions to access the document. This is an integer containing bool values in respective bit positions. For example, if *doc.permissions & pymupdf.PDF_PERM_MODIFY > 0*, you may change the document. See :ref:`PermissionCodes` for details.
For example, if *doc.permissions & pymupdf.PDF_PERM_MODIFY > 0*,
you may change the document.

:type: int

Also see:

* `Document.authenticate()`
* `PermissionCodes`

|history_begin|

* Changed in v1.16.0: This is now an integer comprised of bit indicators. Was a dictionary previously.

|history_end|

.. attribute:: metadata

Contains the document's meta data as a Python dictionary or `None` (if *is_encrypted=True* and *needPass=True*). Keys are *format*, *encryption*, *title*, *author*, *subject*, *keywords*, *creator*, *producer*, *creationDate*, *modDate*, *trapped*. All item values are strings or `None`.
Expand Down
6 changes: 4 additions & 2 deletions docs/the-basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,9 @@ Starting with version 1.16.0, |PDF| decryption and encryption (using passwords)

Method :meth:`Document.authenticate` will automatically establish access rights according to the password used.

The following snippet creates a new |PDF| and encrypts it with separate user and owner passwords. Permissions are granted to print, copy and annotate, but no changes are allowed to someone authenticating with the user password.
The following snippet creates a new |PDF| and encrypts it with separate user and owner passwords.
With the user password, permissions are granted to print, copy and annotate,
but no changes are allowed.


.. code-block:: python
Expand Down Expand Up @@ -1149,4 +1151,4 @@ The following example demonstrates how to do this for each page in a |PDF| docum
.. include:: footer.rst


2 changes: 1 addition & 1 deletion docs/vars.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Document Permissions
----------------------------

====================== =======================================================================
Code Permitted Action
Code Permitted Action with User Password
====================== =======================================================================
PDF_PERM_PRINT Print the document
PDF_PERM_MODIFY Modify the document's contents
Expand Down
Loading