- java.lang.Object
-
- com.itextpdf.text.pdf.PdfEncryptor
-
public final class PdfEncryptor extends java.lang.ObjectThis class takes any PDF and returns exactly the same but encrypted. All the content, links, outlines, etc, are kept. It is also possible to change the info dictionary.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidencrypt(PdfReader reader, java.io.OutputStream os, boolean strength, java.lang.String userPassword, java.lang.String ownerPassword, int permissions)Entry point to encrypt a PDF document.static voidencrypt(PdfReader reader, java.io.OutputStream os, boolean strength, java.lang.String userPassword, java.lang.String ownerPassword, int permissions, java.util.HashMap newInfo)Entry point to encrypt a PDF document.static voidencrypt(PdfReader reader, java.io.OutputStream os, byte[] userPassword, byte[] ownerPassword, int permissions, boolean strength128Bits)Entry point to encrypt a PDF document.static voidencrypt(PdfReader reader, java.io.OutputStream os, byte[] userPassword, byte[] ownerPassword, int permissions, boolean strength128Bits, java.util.HashMap newInfo)Entry point to encrypt a PDF document.static voidencrypt(PdfReader reader, java.io.OutputStream os, int type, java.lang.String userPassword, java.lang.String ownerPassword, int permissions)Entry point to encrypt a PDF document.static voidencrypt(PdfReader reader, java.io.OutputStream os, int type, java.lang.String userPassword, java.lang.String ownerPassword, int permissions, java.util.HashMap newInfo)Entry point to encrypt a PDF document.static java.lang.StringgetPermissionsVerbose(int permissions)Give you a verbose analysis of the permissions.static booleanisAssemblyAllowed(int permissions)Tells you if document assembly is allowed.static booleanisCopyAllowed(int permissions)Tells you if copying is allowed.static booleanisDegradedPrintingAllowed(int permissions)Tells you if degraded printing is allowed.static booleanisFillInAllowed(int permissions)Tells you if filling in fields is allowed.static booleanisModifyAnnotationsAllowed(int permissions)Tells you if modifying annotations is allowed.static booleanisModifyContentsAllowed(int permissions)Tells you if modifying content is allowed.static booleanisPrintingAllowed(int permissions)Tells you if printing is allowed.static booleanisScreenReadersAllowed(int permissions)Tells you if repurposing for screenreaders is allowed.
-
-
-
Method Detail
-
encrypt
public static void encrypt(PdfReader reader, java.io.OutputStream os, byte[] userPassword, byte[] ownerPassword, int permissions, boolean strength128Bits) throws DocumentException, java.io.IOException
Entry point to encrypt a PDF document. The encryption parameters are the same as inPdfWriter. The userPassword and the ownerPassword can be null or have zero length. In this case the ownerPassword is replaced by a random string. The open permissions for the document can be AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. The permissions can be combined by ORing them.- Parameters:
reader- the read PDFos- the output destinationuserPassword- the user password. Can be null or emptyownerPassword- the owner password. Can be null or emptypermissions- the user permissionsstrength128Bits-truefor 128 bit key length,falsefor 40 bit key length- Throws:
DocumentException- on errorjava.io.IOException- on error
-
encrypt
public static void encrypt(PdfReader reader, java.io.OutputStream os, byte[] userPassword, byte[] ownerPassword, int permissions, boolean strength128Bits, java.util.HashMap newInfo) throws DocumentException, java.io.IOException
Entry point to encrypt a PDF document. The encryption parameters are the same as inPdfWriter. The userPassword and the ownerPassword can be null or have zero length. In this case the ownerPassword is replaced by a random string. The open permissions for the document can be AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. The permissions can be combined by ORing them.- Parameters:
reader- the read PDFos- the output destinationuserPassword- the user password. Can be null or emptyownerPassword- the owner password. Can be null or emptypermissions- the user permissionsstrength128Bits-truefor 128 bit key length,falsefor 40 bit key lengthnewInfo- an optionalStringmap to add or change the info dictionary. Entries withnullvalues delete the key in the original info dictionary- Throws:
DocumentException- on errorjava.io.IOException- on error
-
encrypt
public static void encrypt(PdfReader reader, java.io.OutputStream os, boolean strength, java.lang.String userPassword, java.lang.String ownerPassword, int permissions) throws DocumentException, java.io.IOException
Entry point to encrypt a PDF document. The encryption parameters are the same as inPdfWriter. The userPassword and the ownerPassword can be null or have zero length. In this case the ownerPassword is replaced by a random string. The open permissions for the document can be AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. The permissions can be combined by ORing them.- Parameters:
reader- the read PDFos- the output destinationstrength-truefor 128 bit key length,falsefor 40 bit key lengthuserPassword- the user password. Can be null or emptyownerPassword- the owner password. Can be null or emptypermissions- the user permissions- Throws:
DocumentException- on errorjava.io.IOException- on error
-
encrypt
public static void encrypt(PdfReader reader, java.io.OutputStream os, boolean strength, java.lang.String userPassword, java.lang.String ownerPassword, int permissions, java.util.HashMap newInfo) throws DocumentException, java.io.IOException
Entry point to encrypt a PDF document. The encryption parameters are the same as inPdfWriter. The userPassword and the ownerPassword can be null or have zero length. In this case the ownerPassword is replaced by a random string. The open permissions for the document can be AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. The permissions can be combined by ORing them.- Parameters:
reader- the read PDFos- the output destinationstrength-truefor 128 bit key length,falsefor 40 bit key lengthuserPassword- the user password. Can be null or emptyownerPassword- the owner password. Can be null or emptypermissions- the user permissionsnewInfo- an optionalStringmap to add or change the info dictionary. Entries withnullvalues delete the key in the original info dictionary- Throws:
DocumentException- on errorjava.io.IOException- on error
-
encrypt
public static void encrypt(PdfReader reader, java.io.OutputStream os, int type, java.lang.String userPassword, java.lang.String ownerPassword, int permissions, java.util.HashMap newInfo) throws DocumentException, java.io.IOException
Entry point to encrypt a PDF document. The encryption parameters are the same as inPdfWriter. The userPassword and the ownerPassword can be null or have zero length. In this case the ownerPassword is replaced by a random string. The open permissions for the document can be AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. The permissions can be combined by ORing them.- Parameters:
reader- the read PDFos- the output destinationtype- the type of encryption. It can be one of STANDARD_ENCRYPTION_40, STANDARD_ENCRYPTION_128 or ENCRYPTION_AES128. Optionally DO_NOT_ENCRYPT_METADATA can be ored to output the metadata in cleartextuserPassword- the user password. Can be null or emptyownerPassword- the owner password. Can be null or emptypermissions- the user permissionsnewInfo- an optionalStringmap to add or change the info dictionary. Entries withnullvalues delete the key in the original info dictionary- Throws:
DocumentException- on errorjava.io.IOException- on error
-
encrypt
public static void encrypt(PdfReader reader, java.io.OutputStream os, int type, java.lang.String userPassword, java.lang.String ownerPassword, int permissions) throws DocumentException, java.io.IOException
Entry point to encrypt a PDF document. The encryption parameters are the same as inPdfWriter. The userPassword and the ownerPassword can be null or have zero length. In this case the ownerPassword is replaced by a random string. The open permissions for the document can be AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. The permissions can be combined by ORing them.- Parameters:
reader- the read PDFos- the output destinationtype- the type of encryption. It can be one of STANDARD_ENCRYPTION_40, STANDARD_ENCRYPTION_128 or ENCRYPTION_AES128. Optionally DO_NOT_ENCRYPT_METADATA can be ored to output the metadata in cleartextuserPassword- the user password. Can be null or emptyownerPassword- the owner password. Can be null or emptypermissions- the user permissions values delete the key in the original info dictionary- Throws:
DocumentException- on errorjava.io.IOException- on error
-
getPermissionsVerbose
public static java.lang.String getPermissionsVerbose(int permissions)
Give you a verbose analysis of the permissions.- Parameters:
permissions- the permissions value of a PDF file- Returns:
- a String that explains the meaning of the permissions value
-
isPrintingAllowed
public static boolean isPrintingAllowed(int permissions)
Tells you if printing is allowed.- Parameters:
permissions- the permissions value of a PDF file- Returns:
- true if printing is allowed
- Since:
- 2.0.7
-
isModifyContentsAllowed
public static boolean isModifyContentsAllowed(int permissions)
Tells you if modifying content is allowed.- Parameters:
permissions- the permissions value of a PDF file- Returns:
- true if modifying content is allowed
- Since:
- 2.0.7
-
isCopyAllowed
public static boolean isCopyAllowed(int permissions)
Tells you if copying is allowed.- Parameters:
permissions- the permissions value of a PDF file- Returns:
- true if copying is allowed
- Since:
- 2.0.7
-
isModifyAnnotationsAllowed
public static boolean isModifyAnnotationsAllowed(int permissions)
Tells you if modifying annotations is allowed.- Parameters:
permissions- the permissions value of a PDF file- Returns:
- true if modifying annotations is allowed
- Since:
- 2.0.7
-
isFillInAllowed
public static boolean isFillInAllowed(int permissions)
Tells you if filling in fields is allowed.- Parameters:
permissions- the permissions value of a PDF file- Returns:
- true if filling in fields is allowed
- Since:
- 2.0.7
-
isScreenReadersAllowed
public static boolean isScreenReadersAllowed(int permissions)
Tells you if repurposing for screenreaders is allowed.- Parameters:
permissions- the permissions value of a PDF file- Returns:
- true if repurposing for screenreaders is allowed
- Since:
- 2.0.7
-
isAssemblyAllowed
public static boolean isAssemblyAllowed(int permissions)
Tells you if document assembly is allowed.- Parameters:
permissions- the permissions value of a PDF file- Returns:
- true if document assembly is allowed
- Since:
- 2.0.7
-
isDegradedPrintingAllowed
public static boolean isDegradedPrintingAllowed(int permissions)
Tells you if degraded printing is allowed.- Parameters:
permissions- the permissions value of a PDF file- Returns:
- true if degraded printing is allowed
- Since:
- 2.0.7
-
-