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.
Method from org.apache.pdfbox.pdmodel.encryption.AccessPermission Detail: |
public boolean canAssembleDocument() {
return isPermissionBitOn( ASSEMBLE_DOCUMENT_BIT );
}
This will tell if the user can insert/rotate/delete pages. |
public boolean canExtractContent() {
return isPermissionBitOn( EXTRACT_BIT );
}
This will tell if the user can extract text and images from the PDF document. |
public boolean canExtractForAccessibility() {
return isPermissionBitOn( EXTRACT_FOR_ACCESSIBILITY_BIT );
}
This will tell if the user can extract text and images from the PDF document
for accessibility purposes. |
public boolean canFillInForm() {
return isPermissionBitOn( FILL_IN_FORM_BIT );
}
This will tell if the user can fill in interactive forms. |
public boolean canModify() {
return isPermissionBitOn( MODIFICATION_BIT );
}
This will tell if the user can modify contents of the document. |
public boolean canModifyAnnotations() {
return isPermissionBitOn( MODIFY_ANNOTATIONS_BIT );
}
This will tell if the user can add/modify text annotations, fill in interactive forms fields. |
public boolean canPrint() {
return isPermissionBitOn( PRINT_BIT );
}
This will tell if the user can print. |
public boolean canPrintDegraded() {
return isPermissionBitOn( DEGRADED_PRINT_BIT );
}
This will tell if the user can print the document in a degraded format. |
public static AccessPermission getOwnerAccessPermission() {
AccessPermission ret = new AccessPermission();
ret.setCanAssembleDocument(true);
ret.setCanExtractContent(true);
ret.setCanExtractForAccessibility(true);
ret.setCanFillInForm(true);
ret.setCanModify(true);
ret.setCanModifyAnnotations(true);
ret.setCanPrint(true);
ret.setCanPrintDegraded(true);
return ret;
}
returns an access permission object for a document owner. |
public int getPermissionBytes() {
return bytes;
}
The returns an integer representing the access permissions.
This integer can be used for standard PDF encryption as specified
in the PDF specifications. |
public int getPermissionBytesForPublicKey() {
setPermissionBit(1, true);
setPermissionBit(7, false);
setPermissionBit(8, false);
for(int i=13; i< =32; i++)
{
setPermissionBit(i, false);
}
return bytes;
}
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. |
public boolean isOwnerPermission() {
return (this.canAssembleDocument()
&& this.canExtractContent()
&& this.canExtractForAccessibility()
&& this.canFillInForm()
&& this.canModify()
&& this.canModifyAnnotations()
&& this.canPrint()
&& this.canPrintDegraded()
);
}
This will tell if the access permission corresponds to owner
access permission (no restriction). |
public boolean isReadOnly() {
return readOnly;
}
This will tell if the object has been set as read only. |
public void setCanAssembleDocument(boolean allowAssembly) {
if(!readOnly)
{
setPermissionBit( ASSEMBLE_DOCUMENT_BIT, allowAssembly );
}
}
Set if the user can insert/rotate/delete pages.
This method will have no effect if the object is in read only mode |
public void setCanExtractContent(boolean allowExtraction) {
if(!readOnly)
{
setPermissionBit( EXTRACT_BIT, 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 |
public void setCanExtractForAccessibility(boolean allowExtraction) {
if(!readOnly)
{
setPermissionBit( EXTRACT_FOR_ACCESSIBILITY_BIT, 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 |
public void setCanFillInForm(boolean allowFillingInForm) {
if(!readOnly)
{
setPermissionBit( FILL_IN_FORM_BIT, allowFillingInForm );
}
}
Set if the user can fill in interactive forms.
This method will have no effect if the object is in read only mode |
public void setCanModify(boolean allowModifications) {
if(!readOnly)
{
setPermissionBit( MODIFICATION_BIT, allowModifications );
}
}
Set if the user can modify the document.
This method will have no effect if the object is in read only mode |
public void setCanModifyAnnotations(boolean allowAnnotationModification) {
if(!readOnly)
{
setPermissionBit( MODIFY_ANNOTATIONS_BIT, allowAnnotationModification );
}
}
Set if the user can modify annotations.
This method will have no effect if the object is in read only mode |
public void setCanPrint(boolean allowPrinting) {
if(!readOnly)
{
setPermissionBit( PRINT_BIT, allowPrinting );
}
}
Set if the user can print.
This method will have no effect if the object is in read only mode |
public void setCanPrintDegraded(boolean allowAssembly) {
if(!readOnly)
{
setPermissionBit( DEGRADED_PRINT_BIT, allowAssembly );
}
}
Set if the user can print the document in a degraded format.
This method will have no effect if the object is in read only mode |
public void setReadOnly() {
readOnly = true;
}
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 currentAccessPermssion of a document to avoid
users to change access permission. |