Top Description Fields Constructors Methods
org.apache.pdfbox.pdmodel.encryption

public Class AccessPermission

extends Object
Class Inheritance

This class represents the access permissions to a document. These permissions are specified in the PDF format specifications, they include: 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.
Authors
Ben Litchfield, Benoit Guillon
See Also
ProtectionPolicy, org.apache.pdfbox.pdmodel.PDDocument#getCurrentAccessPermission()

Field Summary

Modifier and TypeField and Description
private static final int
private int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private boolean

Constructor Summary

AccessConstructor and Description
public
AccessPermission()

Create a new access permission object.

public
AccessPermission(byte[]
the bytes as defined in PDF specs
b
)

Create a new access permission object from a byte array.

public
AccessPermission(int
The permission bits.
permissions
)

Creates a new access permission object from a single integer.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true If supplied with the user password they are allowed to assemble the document.
canAssembleDocument
()

This will tell if the user can insert/rotate/delete pages.

public boolean

Returns:

true If supplied with the user password they are allowed to extract content from the PDF document
canExtractContent
()

This will tell if the user can extract text and images from the PDF document.

public boolean

Returns:

true If supplied with the user password they are allowed to extract content from the PDF document
canExtractForAccessibility
()

This will tell if the user can extract text and images from the PDF document for accessibility purposes.

public boolean

Returns:

true If supplied with the user password they are allowed to fill in form fields.
canFillInForm
()

This will tell if the user can fill in interactive form fields (including signature fields) even if canModifyAnnotations() returns false.

public boolean

Returns:

true If supplied with the user password they are allowed to modify the document
canModify
()

This will tell if the user can modify contents of the document.

public boolean

Returns:

true If supplied with the user password they are allowed to modify annotations.
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).

public boolean

Returns:

true If supplied with the user password they are allowed to print.
canPrint
()

This will tell if the user can print.

public boolean

Returns:

true If supplied with the user password they are allowed to print the document in a faithful format.
canPrintFaithful
()

This will tell if the user can print the document in a faithful format or in a degraded format (if print is enabled).

public static AccessPermission

Returns:

A standard owner access permission set.
getOwnerAccessPermission
()

returns an access permission object for a document owner.

public int

Returns:

the integer representing the access permissions
getPermissionBytes
()

The returns an integer representing the access permissions.

public int

Returns:

the integer representing access permissions
getPermissionBytesForPublicKey
()

This returns an integer representing the access permissions.

protected boolean

Returns:

true if any revision 3 access permission is set
hasAnyRevision3PermissionSet
()

Indicates if any revision 3 access permission is set or not.

public boolean

Returns:

true if the access permission does not restrict the use of the document
isOwnerPermission
()

This will tell if the access permission corresponds to owner access permission (no restriction).

private boolean
public boolean

Returns:

true if the object is in read only mode.
isReadOnly
()

This will tell if the object has been set as read only.

public void
setCanAssembleDocument(boolean
A boolean determining if the user can assemble the document.
allowAssembly
)

Set if the user can insert/rotate/delete pages.

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

Set if the user can extract content from the document.

public void
setCanExtractForAccessibility(boolean
A boolean determining if the user can extract content from the document.
allowExtraction
)

Set if the user can extract content from the document for accessibility purposes.

public void
setCanFillInForm(boolean
A boolean determining if the user can fill in interactive forms.
allowFillingInForm
)

Set if the user can fill in interactive form fields (including signature fields) even if canModifyAnnotations() returns false.

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

Set if the user can modify the document.

public void
setCanModifyAnnotations(boolean
A boolean determining the new setting.
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).

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

Set if the user can print.

public void
setCanPrintFaithful(boolean
A boolean determining if the user can print the document in a faithful format.
canPrintFaithful
)

Set if the user can print the document in a faithful format or in a degraded format (if print is enabled).

private boolean
setPermissionBit(int bit, boolean value)

public void
setReadOnly()

Locks the access permission read only (ie, the setters will have no effects).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ASSEMBLE_DOCUMENT_BITback to summary
private static final int ASSEMBLE_DOCUMENT_BIT
bytesback to summary
private int bytes
DEFAULT_PERMISSIONSback to summary
private static final int DEFAULT_PERMISSIONS
EXTRACT_BITback to summary
private static final int EXTRACT_BIT
EXTRACT_FOR_ACCESSIBILITY_BITback to summary
private static final int EXTRACT_FOR_ACCESSIBILITY_BIT
FAITHFUL_PRINT_BITback to summary
private static final int FAITHFUL_PRINT_BIT
FILL_IN_FORM_BITback to summary
private static final int FILL_IN_FORM_BIT
MODIFICATION_BITback to summary
private static final int MODIFICATION_BIT
MODIFY_ANNOTATIONS_BITback to summary
private static final int MODIFY_ANNOTATIONS_BIT
readOnlyback to summary
private boolean readOnly

Constructor Detail

AccessPermissionback to summary
public AccessPermission()

Create a new access permission object. By default, all permissions are granted.

AccessPermissionback to summary
public AccessPermission(byte[] b)

Create a new access permission object from a byte array. Bytes are ordered most significant byte first.

Parameters
b:byte[]

the bytes as defined in PDF specs

AccessPermissionback to summary
public AccessPermission(int permissions)

Creates a new access permission object from a single integer.

Parameters
permissions:int

The permission bits.

Method Detail

canAssembleDocumentback to summary
public boolean canAssembleDocument()

This will tell if the user can insert/rotate/delete pages.

Returns:boolean

true If supplied with the user password they are allowed to assemble the document.

canExtractContentback to summary
public boolean canExtractContent()

This will tell if the user can extract text and images from the PDF document.

Returns:boolean

true If supplied with the user password they are allowed to extract content from the PDF document

canExtractForAccessibilityback to summary
public boolean canExtractForAccessibility()

This will tell if the user can extract text and images from the PDF document for accessibility purposes.

Returns:boolean

true If supplied with the user password they are allowed to extract content from the PDF document

canFillInFormback to summary
public boolean canFillInForm()

This will tell if the user can fill in interactive form fields (including signature fields) even if canModifyAnnotations() returns false.

Returns:boolean

true If supplied with the user password they are allowed to fill in form fields.

canModifyback to summary
public boolean canModify()

This will tell if the user can modify contents of the document.

Returns:boolean

true If supplied with the user password they are allowed to modify the document

canModifyAnnotationsback to summary
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:boolean

true If supplied with the user password they are allowed to modify annotations.

canPrintback to summary
public boolean canPrint()

This will tell if the user can print.

Returns:boolean

true If supplied with the user password they are allowed to print.

canPrintFaithfulback to summary
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:boolean

true If supplied with the user password they are allowed to print the document in a faithful format.

getOwnerAccessPermissionback to summary
public static AccessPermission getOwnerAccessPermission()

returns an access permission object for a document owner.

Returns:AccessPermission

A standard owner access permission set.

getPermissionBytesback to summary
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:int

the integer representing the access permissions

getPermissionBytesForPublicKeyback to summary
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:int

the integer representing access permissions

hasAnyRevision3PermissionSetback to summary
protected boolean hasAnyRevision3PermissionSet()

Indicates if any revision 3 access permission is set or not.

Returns:boolean

true if any revision 3 access permission is set

isOwnerPermissionback to summary
public boolean isOwnerPermission()

This will tell if the access permission corresponds to owner access permission (no restriction).

Returns:boolean

true if the access permission does not restrict the use of the document

isPermissionBitOnback to summary
private boolean isPermissionBitOn(int bit)
isReadOnlyback to summary
public boolean isReadOnly()

This will tell if the object has been set as read only.

Returns:boolean

true if the object is in read only mode.

setCanAssembleDocumentback to summary
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:boolean

A boolean determining if the user can assemble the document.

setCanExtractContentback to summary
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:boolean

A boolean determining if the user can extract content from the document.

setCanExtractForAccessibilityback to summary
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:boolean

A boolean determining if the user can extract content from the document.

setCanFillInFormback to summary
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:boolean

A boolean determining if the user can fill in interactive forms.

setCanModifyback to summary
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:boolean

A boolean determining if the user can modify the document.

setCanModifyAnnotationsback to summary
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:boolean

A boolean determining the new setting.

setCanPrintback to summary
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:boolean

A boolean determining if the user can print.

setCanPrintFaithfulback to summary
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:boolean

A boolean determining if the user can print the document in a faithful format.

setPermissionBitback to summary
private boolean setPermissionBit(int bit, boolean value)
setReadOnlyback to summary
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.