Class AccessPermission

java.lang.Object
org.apache.pdfbox.pdmodel.encryption.AccessPermission

public class AccessPermission extends Object
This class represents the access permissions to a document. These permissions are specified in the PDF format specifications, they include:
  • print the document
  • modify the content of the document
  • copy or extract content of the document
  • add or modify annotations
  • fill in interactive form fields
  • extract text and graphics for accessibility to visually impaired people
  • assemble the document
  • print in degraded quality
This class can be used to protect a document by assigning access permissions to recipients. In this case, it must be used with a specific ProtectionPolicy. When a document is decrypted, it has a currentAccessPermission property which is the access permissions granted to the user who decrypted the document.
Author:
Ben Litchfield, Benoit Guillon
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new access permission object.
    AccessPermission(byte[] b)
    Create a new access permission object from a byte array.
    AccessPermission(int permissions)
    Creates a new access permission object from a single integer.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    This will tell if the user can insert/rotate/delete pages.
    boolean
    This will tell if the user can extract text and images from the PDF document.
    boolean
    This will tell if the user can extract text and images from the PDF document for accessibility purposes.
    boolean
    This will tell if the user can fill in interactive form fields (including signature fields) even if canModifyAnnotations() returns false.
    boolean
    This will tell if the user can modify contents of the document.
    boolean
    This will tell if the user can add or modify text annotations and fill in interactive forms fields and, if canModify() returns true, create or modify interactive form fields (including signature fields).
    boolean
    This will tell if the user can print.
    boolean
    Deprecated.
    boolean
    This will tell if the user can print the document in a faithful format or in a degraded format (if print is enabled).
    returns an access permission object for a document owner.
    int
    The returns an integer representing the access permissions.
    int
    This returns an integer representing the access permissions.
    protected boolean
    Indicates if any revision 3 access permission is set or not.
    boolean
    This will tell if the access permission corresponds to owner access permission (no restriction).
    boolean
    This will tell if the object has been set as read only.
    void
    setCanAssembleDocument(boolean allowAssembly)
    Set if the user can insert/rotate/delete pages.
    void
    setCanExtractContent(boolean allowExtraction)
    Set if the user can extract content from the document.
    void
    setCanExtractForAccessibility(boolean allowExtraction)
    Set if the user can extract content from the document for accessibility purposes.
    void
    setCanFillInForm(boolean allowFillingInForm)
    Set if the user can fill in interactive form fields (including signature fields) even if canModifyAnnotations() returns false.
    void
    setCanModify(boolean allowModifications)
    Set if the user can modify the document.
    void
    setCanModifyAnnotations(boolean allowAnnotationModification)
    Set if the user can add or modify text annotations and fill in interactive forms fields and, if canModify() returns true, create or modify interactive form fields (including signature fields).
    void
    setCanPrint(boolean allowPrinting)
    Set if the user can print.
    void
    setCanPrintDegraded(boolean canPrintFaithful)
    void
    setCanPrintFaithful(boolean canPrintFaithful)
    Set if the user can print the document in a faithful format or in a degraded format (if print is enabled).
    void
    Locks the access permission read only (ie, the setters will have no effects).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AccessPermission

      public AccessPermission()
      Create a new access permission object. By default, all permissions are granted.
    • AccessPermission

      public AccessPermission(byte[] b)
      Create a new access permission object from a byte array. Bytes are ordered most significant byte first.
      Parameters:
      b - the bytes as defined in PDF specs
    • AccessPermission

      public AccessPermission(int permissions)
      Creates a new access permission object from a single integer.
      Parameters:
      permissions - The permission bits.
  • Method Details

    • isOwnerPermission

      public boolean isOwnerPermission()
      This will tell if the access permission corresponds to owner access permission (no restriction).
      Returns:
      true if the access permission does not restrict the use of the document
    • getOwnerAccessPermission

      public static AccessPermission getOwnerAccessPermission()
      returns an access permission object for a document owner.
      Returns:
      A standard owner access permission set.
    • getPermissionBytesForPublicKey

      public int getPermissionBytesForPublicKey()
      This returns an integer representing the access permissions. This integer can be used for public key encryption. This format is not documented in the PDF specifications but is necessary for compatibility with Adobe Acrobat and Adobe Reader.
      Returns:
      the integer representing access permissions
    • getPermissionBytes

      public int getPermissionBytes()
      The returns an integer representing the access permissions. This integer can be used for standard PDF encryption as specified in the PDF specifications.
      Returns:
      the integer representing the access permissions
    • canPrint

      public boolean canPrint()
      This will tell if the user can print.
      Returns:
      true If supplied with the user password they are allowed to print.
    • setCanPrint

      public void setCanPrint(boolean allowPrinting)
      Set if the user can print.

      This method will have no effect if the object is in read only mode.

      Parameters:
      allowPrinting - A boolean determining if the user can print.
    • canModify

      public boolean canModify()
      This will tell if the user can modify contents of the document.
      Returns:
      true If supplied with the user password they are allowed to modify the document
    • setCanModify

      public void setCanModify(boolean allowModifications)
      Set if the user can modify the document.

      This method will have no effect if the object is in read only mode.

      Parameters:
      allowModifications - A boolean determining if the user can modify the document.
    • canExtractContent

      public boolean canExtractContent()
      This will tell if the user can extract text and images from the PDF document.
      Returns:
      true If supplied with the user password they are allowed to extract content from the PDF document
    • setCanExtractContent

      public void setCanExtractContent(boolean allowExtraction)
      Set if the user can extract content from the document.

      This method will have no effect if the object is in read only mode.

      Parameters:
      allowExtraction - A boolean determining if the user can extract content from the document.
    • canModifyAnnotations

      public boolean canModifyAnnotations()
      This will tell if the user can add or modify text annotations and fill in interactive forms fields and, if canModify() returns true, create or modify interactive form fields (including signature fields). Note that if canFillInForm() returns true, it is still possible to fill in interactive forms (including signature fields) even if this method here returns false.
      Returns:
      true If supplied with the user password they are allowed to modify annotations.
    • setCanModifyAnnotations

      public void setCanModifyAnnotations(boolean allowAnnotationModification)
      Set if the user can add or modify text annotations and fill in interactive forms fields and, if canModify() returns true, create or modify interactive form fields (including signature fields). Note that if canFillInForm() returns true, it is still possible to fill in interactive forms (including signature fields) even the parameter here is false.

      This method will have no effect if the object is in read only mode.

      Parameters:
      allowAnnotationModification - A boolean determining the new setting.
    • canFillInForm

      public boolean canFillInForm()
      This will tell if the user can fill in interactive form fields (including signature fields) even if canModifyAnnotations() returns false.
      Returns:
      true If supplied with the user password they are allowed to fill in form fields.
    • setCanFillInForm

      public void setCanFillInForm(boolean allowFillingInForm)
      Set if the user can fill in interactive form fields (including signature fields) even if canModifyAnnotations() returns false. Therefore, if you want to prevent a user from filling in interactive form fields, you need to call setCanModifyAnnotations(false) as well.

      This method will have no effect if the object is in read only mode.

      Parameters:
      allowFillingInForm - A boolean determining if the user can fill in interactive forms.
    • canExtractForAccessibility

      public boolean canExtractForAccessibility()
      This will tell if the user can extract text and images from the PDF document for accessibility purposes.
      Returns:
      true If supplied with the user password they are allowed to extract content from the PDF document
    • setCanExtractForAccessibility

      public void setCanExtractForAccessibility(boolean allowExtraction)
      Set if the user can extract content from the document for accessibility purposes.

      This method will have no effect if the object is in read only mode.

      Parameters:
      allowExtraction - A boolean determining if the user can extract content from the document.
    • canAssembleDocument

      public boolean canAssembleDocument()
      This will tell if the user can insert/rotate/delete pages.
      Returns:
      true If supplied with the user password they are allowed to assemble the document.
    • setCanAssembleDocument

      public void setCanAssembleDocument(boolean allowAssembly)
      Set if the user can insert/rotate/delete pages.

      This method will have no effect if the object is in read only mode.

      Parameters:
      allowAssembly - A boolean determining if the user can assemble the document.
    • canPrintDegraded

      @Deprecated public boolean canPrintDegraded()
      Deprecated.
      This will tell if the user can print the document in a faithful format or in a degraded format (if print is enabled).
      Returns:
      true If supplied with the user password they are allowed to print the document in a faithful format.
    • setCanPrintDegraded

      @Deprecated public void setCanPrintDegraded(boolean canPrintFaithful)
      Set if the user can print the document in a faithful format or in a degraded format (if print is enabled). The PDF version must be 1.5 or higher.

      This method will have no effect if the object is in read only mode.

      Parameters:
      canPrintFaithful - A boolean determining if the user can print the document in a faithful format.
    • canPrintFaithful

      public boolean canPrintFaithful()
      This will tell if the user can print the document in a faithful format or in a degraded format (if print is enabled).
      Returns:
      true If supplied with the user password they are allowed to print the document in a degraded format.
    • setCanPrintFaithful

      public void setCanPrintFaithful(boolean canPrintFaithful)
      Set if the user can print the document in a faithful format or in a degraded format (if print is enabled). The PDF version must be 1.5 or higher.

      This method will have no effect if the object is in read only mode.

      Parameters:
      canPrintFaithful - A boolean determining if the user can print the document in a degraded format.
    • setReadOnly

      public void setReadOnly()
      Locks the access permission read only (ie, the setters will have no effects). After that, the object cannot be unlocked. This method is used for the currentAccessPermission of a document to avoid users to change access permission.
    • isReadOnly

      public boolean isReadOnly()
      This will tell if the object has been set as read only.
      Returns:
      true if the object is in read only mode.
    • hasAnyRevision3PermissionSet

      protected boolean hasAnyRevision3PermissionSet()
      Indicates if any revision 3 access permission is set or not.
      Returns:
      true if any revision 3 access permission is set