aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/pdfbox/pdmodel/encryption
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/pdfbox/pdmodel/encryption')
-rw-r--r--src/main/java/org/pdfbox/pdmodel/encryption/PDEncryptionDictionary.java193
-rw-r--r--src/main/java/org/pdfbox/pdmodel/encryption/PDEncryptionManager.java131
-rw-r--r--src/main/java/org/pdfbox/pdmodel/encryption/PDStandardEncryption.java416
-rw-r--r--src/main/java/org/pdfbox/pdmodel/encryption/package.html9
4 files changed, 749 insertions, 0 deletions
diff --git a/src/main/java/org/pdfbox/pdmodel/encryption/PDEncryptionDictionary.java b/src/main/java/org/pdfbox/pdmodel/encryption/PDEncryptionDictionary.java
new file mode 100644
index 0000000..08f18fb
--- /dev/null
+++ b/src/main/java/org/pdfbox/pdmodel/encryption/PDEncryptionDictionary.java
@@ -0,0 +1,193 @@
+/**
+ * Copyright (c) 2003, www.pdfbox.org
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of pdfbox; nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://www.pdfbox.org
+ *
+ */
+package org.pdfbox.pdmodel.encryption;
+
+import org.pdfbox.cos.COSDictionary;
+import org.pdfbox.cos.COSInteger;
+import org.pdfbox.cos.COSName;
+import org.pdfbox.cos.COSNumber;
+
+/**
+ * This represents the base class for encryption dictionaries. All PDF implementations
+ * are expected to implement the Standard encryption algorithm, but others can be plugged in.
+ *
+ * See PDF Reference 1.4 section "3.5 Encryption"
+ *
+ * @author Ben Litchfield (ben@csh.rit.edu)
+ * @version $Revision: 1.5 $
+ */
+public abstract class PDEncryptionDictionary
+{
+ /**
+ * See PDF Reference 1.4 Table 3.13.
+ */
+ public static final int VERSION0_UNDOCUMENTED_UNSUPPORTED = 0;
+ /**
+ * See PDF Reference 1.4 Table 3.13.
+ */
+ public static final int VERSION1_40_BIT_ALGORITHM = 1;
+ /**
+ * See PDF Reference 1.4 Table 3.13.
+ */
+ public static final int VERSION2_VARIABLE_LENGTH_ALGORITHM = 2;
+ /**
+ * See PDF Reference 1.4 Table 3.13.
+ */
+ public static final int VERSION3_UNPUBLISHED_ALGORITHM = 3;
+ /**
+ * See PDF Reference 1.4 Table 3.13.
+ */
+ public static final int VERSION4_SECURITY_HANDLER = 4;
+
+ /**
+ * The default security handler.
+ */
+ public static final String DEFAULT_NAME = "Standard";
+
+ /**
+ * The default length for the encryption key.
+ */
+ public static final int DEFAULT_LENGTH = 40;
+
+ /**
+ * The default version, according to the PDF Reference.
+ */
+ public static final int DEFAULT_VERSION = VERSION0_UNDOCUMENTED_UNSUPPORTED;
+
+ /**
+ * The cos model wrapped object.
+ */
+ protected COSDictionary encryptionDictionary = null;
+
+ /**
+ * Constructor.
+ *
+ * @param dictionary The pre-existing encryption dictionary.
+ */
+ protected PDEncryptionDictionary( COSDictionary dictionary )
+ {
+ encryptionDictionary = dictionary;
+ }
+
+ /**
+ * Constructor, sub classes need to fill out the required fields.
+ */
+ protected PDEncryptionDictionary()
+ {
+ encryptionDictionary = new COSDictionary();
+ setLength( DEFAULT_LENGTH );
+ setVersion( DEFAULT_VERSION );
+ }
+
+ /**
+ * This will get the dictionary associated with this encryption dictionary.
+ *
+ * @return The COS dictionary that this object wraps.
+ */
+ public COSDictionary getCOSDictionary()
+ {
+ return encryptionDictionary;
+ }
+
+ /**
+ * Read-only field of the encryption filter name. The default value is
+ * "Standard" for the built in security handler.
+ *
+ * @return The name of the encryption handler.
+ */
+ public String getFilter()
+ {
+ String filter = DEFAULT_NAME;
+ COSName cosFilter = (COSName)encryptionDictionary.getDictionaryObject( COSName.FILTER );
+ if( cosFilter != null )
+ {
+ filter = cosFilter.getName();
+ }
+ return filter;
+ }
+
+ /**
+ * This will return the V entry of the encryption dictionary.<br /><br />
+ * See PDF Reference 1.4 Table 3.13.
+ *
+ * @return The encryption version to use.
+ */
+ public int getVersion()
+ {
+ int version = DEFAULT_VERSION;
+ COSNumber cosVersion = (COSNumber)encryptionDictionary.getDictionaryObject( COSName.getPDFName( "V" ) );
+ if( cosVersion != null )
+ {
+ version = cosVersion.intValue();
+ }
+ return version;
+ }
+
+ /**
+ * This will set the V entry of the encryption dictionary.<br /><br />
+ * See PDF Reference 1.4 Table 3.13. <br /><br/>
+ * <b>Note: This value is used to decrypt the pdf document. If you change this when
+ * the document is encrypted then decryption will fail!.</b>
+ *
+ * @param version The new encryption version.
+ */
+ public void setVersion( int version )
+ {
+ encryptionDictionary.setItem( COSName.getPDFName( "V" ), new COSInteger( version ) );
+ }
+
+ /**
+ * This will return the Length entry of the encryption dictionary.<br /><br />
+ * The length in <b>bits</b> for the encryption algorithm. This will return a multiple of 8.
+ *
+ * @return The length in bits for the encryption algorithm
+ */
+ public int getLength()
+ {
+ int length = DEFAULT_LENGTH;
+ COSNumber cosLength = (COSNumber)encryptionDictionary.getDictionaryObject( COSName.LENGTH );
+ if( cosLength != null )
+ {
+ length = cosLength.intValue();
+ }
+ return length;
+ }
+
+ /**
+ * This will set the number of bits to use for the encryption algorithm.
+ *
+ * @param length The new key length.
+ */
+ public void setLength( int length )
+ {
+ encryptionDictionary.setItem( COSName.LENGTH, new COSInteger( length ) );
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/pdfbox/pdmodel/encryption/PDEncryptionManager.java b/src/main/java/org/pdfbox/pdmodel/encryption/PDEncryptionManager.java
new file mode 100644
index 0000000..9dfc36e
--- /dev/null
+++ b/src/main/java/org/pdfbox/pdmodel/encryption/PDEncryptionManager.java
@@ -0,0 +1,131 @@
+/**
+ * Copyright (c) 2003-2004, www.pdfbox.org
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of pdfbox; nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://www.pdfbox.org
+ *
+ */
+package org.pdfbox.pdmodel.encryption;
+
+import org.pdfbox.cos.COSDictionary;
+import org.pdfbox.cos.COSName;
+import java.io.IOException;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * This class will handle loading of the different security handlers.
+ *
+ * See PDF Reference 1.4 section "3.5 Encryption"
+ *
+ * @author Ben Litchfield (ben@csh.rit.edu)
+ * @version $Revision: 1.5 $
+ */
+public class PDEncryptionManager
+{
+ private static Map handlerMap = Collections.synchronizedMap( new HashMap() );
+
+ static
+ {
+ registerSecurityHandler( PDStandardEncryption.FILTER_NAME, PDStandardEncryption.class );
+ }
+
+ private PDEncryptionManager()
+ {
+ }
+
+ /**
+ * This will allow the user to register new security handlers when unencrypting a
+ * document.
+ *
+ * @param filterName As described in the encryption dictionary.
+ * @param handlerClass A subclass of PDEncryptionDictionary that has a constructor that takes
+ * a COSDictionary.
+ */
+ public static void registerSecurityHandler( String filterName, Class handlerClass )
+ {
+ handlerMap.put( COSName.getPDFName( filterName ), handlerClass );
+ }
+
+ /**
+ * This will get the correct security handler for the encryption dictionary.
+ *
+ * @param dictionary The encryption dictionary.
+ *
+ * @return An implementation of PDEncryptionDictionary(PDStandardEncryption for most cases).
+ *
+ * @throws IOException If a security handler could not be found.
+ */
+ public static PDEncryptionDictionary getEncryptionDictionary( COSDictionary dictionary )
+ throws IOException
+ {
+ Object retval = null;
+ if( dictionary != null )
+ {
+ COSName filter = (COSName)dictionary.getDictionaryObject( COSName.FILTER );
+ Class handlerClass = (Class)handlerMap.get( filter );
+ if( handlerClass == null )
+ {
+ throw new IOException( "No handler for security handler '" + filter.getName() + "'" );
+ }
+ else
+ {
+ try
+ {
+ Constructor ctor = handlerClass.getConstructor( new Class[] {
+ COSDictionary.class
+ } );
+ retval = ctor.newInstance( new Object[] {
+ dictionary
+ } );
+ }
+ catch( NoSuchMethodException e )
+ {
+ throw new IOException( e.getMessage() );
+ }
+ catch( InstantiationException e )
+ {
+ throw new IOException( e.getMessage() );
+ }
+ catch( IllegalAccessException e )
+ {
+ throw new IOException( e.getMessage() );
+ }
+ catch( InvocationTargetException e )
+ {
+ throw new IOException( e.getMessage() );
+ }
+ }
+ }
+ return (PDEncryptionDictionary)retval;
+
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/pdfbox/pdmodel/encryption/PDStandardEncryption.java b/src/main/java/org/pdfbox/pdmodel/encryption/PDStandardEncryption.java
new file mode 100644
index 0000000..5b3be3b
--- /dev/null
+++ b/src/main/java/org/pdfbox/pdmodel/encryption/PDStandardEncryption.java
@@ -0,0 +1,416 @@
+/**
+ * Copyright (c) 2003, www.pdfbox.org
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of pdfbox; nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://www.pdfbox.org
+ *
+ */
+package org.pdfbox.pdmodel.encryption;
+
+import org.pdfbox.cos.COSDictionary;
+import org.pdfbox.cos.COSInteger;
+import org.pdfbox.cos.COSName;
+import org.pdfbox.cos.COSNumber;
+import org.pdfbox.cos.COSString;
+
+import java.io.IOException;
+
+/**
+ * This class holds information that is related to the standard PDF encryption.
+ *
+ * See PDF Reference 1.4 section "3.5 Encryption"
+ *
+ * @author Ben Litchfield (ben@csh.rit.edu)
+ * @version $Revision: 1.5 $
+ */
+public class PDStandardEncryption extends PDEncryptionDictionary
+{
+ /**
+ * The 'Filter' name for this security handler.
+ */
+ public static final String FILTER_NAME = "Standard";
+
+ /**
+ * The default revision of one is not specified.
+ */
+ public static final int DEFAULT_REVISION = 3;
+
+ /**
+ * Encryption revision 2.
+ */
+ public static final int REVISION2 = 2;
+ /**
+ * Encryption revision 3.
+ */
+ public static final int REVISION3 = 3;
+ /**
+ * Encryption revision 4.
+ */
+ public static final int REVISION4 = 4;
+
+ /**
+ * The default set of permissions which is to allow all.
+ */
+ public static final int DEFAULT_PERMISSIONS = 0xFFFFFFFF ^ 3;//bits 0 & 1 need to be zero
+
+ private static final int PRINT_BIT = 3;
+ private static final int MODIFICATION_BIT = 4;
+ private static final int EXTRACT_BIT = 5;
+ private static final int MODIFY_ANNOTATIONS_BIT = 6;
+ private static final int FILL_IN_FORM_BIT = 9;
+ private static final int EXTRACT_FOR_ACCESSIBILITY_BIT = 10;
+ private static final int ASSEMBLE_DOCUMENT_BIT = 11;
+ private static final int DEGRADED_PRINT_BIT = 12;
+
+ /**
+ * Default constructor that uses Version 2, Revision 3, 40 bit encryption,
+ * all permissions allowed.
+ */
+ public PDStandardEncryption()
+ {
+ super();
+ encryptionDictionary.setItem( COSName.FILTER, COSName.getPDFName( FILTER_NAME ) );
+ setVersion( PDEncryptionDictionary.VERSION1_40_BIT_ALGORITHM );
+ setRevision( PDStandardEncryption.REVISION2 );
+ setPermissions( DEFAULT_PERMISSIONS );
+ }
+
+ /**
+ * Constructor from existing dictionary.
+ *
+ * @param dict The existing encryption dictionary.
+ */
+ public PDStandardEncryption( COSDictionary dict )
+ {
+ super( dict );
+ }
+
+ /**
+ * This will return the R entry of the encryption dictionary.<br /><br />
+ * See PDF Reference 1.4 Table 3.14.
+ *
+ * @return The encryption revision to use.
+ */
+ public int getRevision()
+ {
+ int revision = DEFAULT_VERSION;
+ COSNumber cosRevision = (COSNumber)encryptionDictionary.getDictionaryObject( COSName.getPDFName( "R" ) );
+ if( cosRevision != null )
+ {
+ revision = cosRevision.intValue();
+ }
+ return revision;
+ }
+
+ /**
+ * This will set the R entry of the encryption dictionary.<br /><br />
+ * See PDF Reference 1.4 Table 3.14. <br /><br/>
+ *
+ * <b>Note: This value is used to decrypt the pdf document. If you change this when
+ * the document is encrypted then decryption will fail!.</b>
+ *
+ * @param revision The new encryption version.
+ */
+ public void setRevision( int revision )
+ {
+ encryptionDictionary.setItem( COSName.getPDFName( "R" ), new COSInteger( revision ) );
+ }
+
+ /**
+ * This will get the O entry in the standard encryption dictionary.
+ *
+ * @return A 32 byte array or null if there is no owner key.
+ */
+ public byte[] getOwnerKey()
+ {
+ byte[] o = null;
+ COSString owner = (COSString)encryptionDictionary.getDictionaryObject( COSName.getPDFName( "O" ) );
+ if( owner != null )
+ {
+ o = owner.getBytes();
+ }
+ return o;
+ }
+
+ /**
+ * This will set the O entry in the standard encryption dictionary.
+ *
+ * @param o A 32 byte array or null if there is no owner key.
+ *
+ * @throws IOException If there is an error setting the data.
+ */
+ public void setOwnerKey( byte[] o ) throws IOException
+ {
+ COSString owner = new COSString();
+ owner.append( o );
+ encryptionDictionary.setItem( COSName.getPDFName( "O" ), owner );
+ }
+
+ /**
+ * This will get the U entry in the standard encryption dictionary.
+ *
+ * @return A 32 byte array or null if there is no user key.
+ */
+ public byte[] getUserKey()
+ {
+ byte[] u = null;
+ COSString user = (COSString)encryptionDictionary.getDictionaryObject( COSName.getPDFName( "U" ) );
+ if( user != null )
+ {
+ u = user.getBytes();
+ }
+ return u;
+ }
+
+ /**
+ * This will set the U entry in the standard encryption dictionary.
+ *
+ * @param u A 32 byte array.
+ *
+ * @throws IOException If there is an error setting the data.
+ */
+ public void setUserKey( byte[] u ) throws IOException
+ {
+ COSString user = new COSString();
+ user.append( u );
+ encryptionDictionary.setItem( COSName.getPDFName( "U" ), user );
+ }
+
+ /**
+ * This will get the permissions bit mask.
+ *
+ * @return The permissions bit mask.
+ */
+ public int getPermissions()
+ {
+ int permissions = 0;
+ COSInteger p = (COSInteger)encryptionDictionary.getDictionaryObject( COSName.getPDFName( "P" ) );
+ if( p != null )
+ {
+ permissions = p.intValue();
+ }
+ return permissions;
+ }
+
+ /**
+ * This will set the permissions bit mask.
+ *
+ * @param p The new permissions bit mask
+ */
+ public void setPermissions( int p )
+ {
+ encryptionDictionary.setItem( COSName.getPDFName( "P" ), new COSInteger( p ) );
+ }
+
+ private boolean isPermissionBitOn( int bit )
+ {
+ return (getPermissions() & (1 << (bit-1))) != 0;
+ }
+
+ private boolean setPermissionBit( int bit, boolean value )
+ {
+ int permissions = getPermissions();
+ if( value )
+ {
+ permissions = permissions | (1 << (bit-1));
+ }
+ else
+ {
+ permissions = permissions & (0xFFFFFFFF ^ (1 << (bit-1)));
+ }
+ setPermissions( permissions );
+
+ return (getPermissions() & (1 << (bit-1))) != 0;
+ }
+
+ /**
+ * This will tell if the user can print.
+ *
+ * @return true If supplied with the user password they are allowed to print.
+ */
+ public boolean canPrint()
+ {
+ return isPermissionBitOn( PRINT_BIT );
+ }
+
+ /**
+ * Set if the user can print.
+ *
+ * @param allowPrinting A boolean determining if the user can print.
+ */
+ public void setCanPrint( boolean allowPrinting )
+ {
+ setPermissionBit( PRINT_BIT, allowPrinting );
+ }
+
+ /**
+ * This will tell if the user can modify contents of the document.
+ *
+ * @return true If supplied with the user password they are allowed to modify the document
+ */
+ public boolean canModify()
+ {
+ return isPermissionBitOn( MODIFICATION_BIT );
+ }
+
+ /**
+ * Set if the user can modify the document.
+ *
+ * @param allowModifications A boolean determining if the user can modify the document.
+ */
+ public void setCanModify( boolean allowModifications )
+ {
+ setPermissionBit( MODIFICATION_BIT, allowModifications );
+ }
+
+ /**
+ * This will tell if the user can extract text and images from the PDF document.
+ *
+ * @return true If supplied with the user password they are allowed to extract content
+ * from the PDF document
+ */
+ public boolean canExtractContent()
+ {
+ return isPermissionBitOn( EXTRACT_BIT );
+ }
+
+ /**
+ * Set if the user can extract content from the document.
+ *
+ * @param allowExtraction A boolean determining if the user can extract content
+ * from the document.
+ */
+ public void setCanExtractContent( boolean allowExtraction )
+ {
+ setPermissionBit( EXTRACT_BIT, allowExtraction );
+ }
+
+ /**
+ * This will tell if the user can add/modify text annotations, fill in interactive forms fields.
+ *
+ * @return true If supplied with the user password they are allowed to modify annotations.
+ */
+ public boolean canModifyAnnotations()
+ {
+ return isPermissionBitOn( MODIFY_ANNOTATIONS_BIT );
+ }
+
+ /**
+ * Set if the user can modify annotations.
+ *
+ * @param allowAnnotationModification A boolean determining if the user can modify annotations.
+ */
+ public void setCanModifyAnnotations( boolean allowAnnotationModification )
+ {
+ setPermissionBit( MODIFY_ANNOTATIONS_BIT, allowAnnotationModification );
+ }
+
+ /**
+ * This will tell if the user can fill in interactive forms.
+ *
+ * @return true If supplied with the user password they are allowed to fill in form fields.
+ */
+ public boolean canFillInForm()
+ {
+ return isPermissionBitOn( FILL_IN_FORM_BIT );
+ }
+
+ /**
+ * Set if the user can fill in interactive forms.
+ *
+ * @param allowFillingInForm A boolean determining if the user can fill in interactive forms.
+ */
+ public void setCanFillInForm( boolean allowFillingInForm )
+ {
+ setPermissionBit( FILL_IN_FORM_BIT, allowFillingInForm );
+ }
+
+ /**
+ * This will tell if the user can extract text and images from the PDF document
+ * for accessibility purposes.
+ *
+ * @return true If supplied with the user password they are allowed to extract content
+ * from the PDF document
+ */
+ public boolean canExtractForAccessibility()
+ {
+ return isPermissionBitOn( EXTRACT_FOR_ACCESSIBILITY_BIT );
+ }
+
+ /**
+ * Set if the user can extract content from the document for accessibility purposes.
+ *
+ * @param allowExtraction A boolean determining if the user can extract content
+ * from the document.
+ */
+ public void setCanExtractForAccessibility( boolean allowExtraction )
+ {
+ setPermissionBit( EXTRACT_FOR_ACCESSIBILITY_BIT, allowExtraction );
+ }
+
+ /**
+ * This will tell if the user can insert/rotate/delete pages.
+ *
+ * @return true If supplied with the user password they are allowed to extract content
+ * from the PDF document
+ */
+ public boolean canAssembleDocument()
+ {
+ return isPermissionBitOn( ASSEMBLE_DOCUMENT_BIT );
+ }
+
+ /**
+ * Set if the user can insert/rotate/delete pages.
+ *
+ * @param allowAssembly A boolean determining if the user can assemble the document.
+ */
+ public void setCanAssembleDocument( boolean allowAssembly )
+ {
+ setPermissionBit( ASSEMBLE_DOCUMENT_BIT, allowAssembly );
+ }
+
+ /**
+ * This will tell if the user can print the document in a degraded format.
+ *
+ * @return true If supplied with the user password they are allowed to print the
+ * document in a degraded format.
+ */
+ public boolean canPrintDegraded()
+ {
+ return isPermissionBitOn( DEGRADED_PRINT_BIT );
+ }
+
+ /**
+ * Set if the user can print the document in a degraded format.
+ *
+ * @param allowAssembly A boolean determining if the user can print the
+ * document in a degraded format.
+ */
+ public void setCanPrintDegraded( boolean allowAssembly )
+ {
+ setPermissionBit( DEGRADED_PRINT_BIT, allowAssembly );
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/pdfbox/pdmodel/encryption/package.html b/src/main/java/org/pdfbox/pdmodel/encryption/package.html
new file mode 100644
index 0000000..a458817
--- /dev/null
+++ b/src/main/java/org/pdfbox/pdmodel/encryption/package.html
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+
+</head>
+<body>
+The encryption package will handle the PDF document security handlers and the functionality of pluggable security handlers.
+</body>
+</html>