public final class PdfEncryptor extends Object
Modifier and Type | Method and Description |
---|---|
static void |
encrypt(PdfReader reader,
OutputStream os,
boolean strength,
String userPassword,
String ownerPassword,
int permissions)
Entry point to encrypt a PDF document.
|
static void |
encrypt(PdfReader reader,
OutputStream os,
boolean strength,
String userPassword,
String ownerPassword,
int permissions,
Map<String,String> newInfo)
Entry point to encrypt a PDF document.
|
static void |
encrypt(PdfReader reader,
OutputStream os,
byte[] userPassword,
byte[] ownerPassword,
int permissions,
boolean strength128Bits)
Entry point to encrypt a PDF document.
|
static void |
encrypt(PdfReader reader,
OutputStream os,
byte[] userPassword,
byte[] ownerPassword,
int permissions,
boolean strength128Bits,
Map<String,String> newInfo)
Entry point to encrypt a PDF document.
|
static void |
encrypt(PdfReader reader,
OutputStream os,
int type,
String userPassword,
String ownerPassword,
int permissions)
Entry point to encrypt a PDF document.
|
static void |
encrypt(PdfReader reader,
OutputStream os,
int type,
String userPassword,
String ownerPassword,
int permissions,
Map<String,String> newInfo)
Entry point to encrypt a PDF document.
|
static String |
getPermissionsVerbose(int permissions)
Give you a verbose analysis of the permissions.
|
static boolean |
isAssemblyAllowed(int permissions)
Tells you if document assembly is allowed.
|
static boolean |
isCopyAllowed(int permissions)
Tells you if copying is allowed.
|
static boolean |
isDegradedPrintingAllowed(int permissions)
Tells you if degraded printing is allowed.
|
static boolean |
isFillInAllowed(int permissions)
Tells you if filling in fields is allowed.
|
static boolean |
isModifyAnnotationsAllowed(int permissions)
Tells you if modifying annotations is allowed.
|
static boolean |
isModifyContentsAllowed(int permissions)
Tells you if modifying content is allowed.
|
static boolean |
isPrintingAllowed(int permissions)
Tells you if printing is allowed.
|
static boolean |
isScreenReadersAllowed(int permissions)
Tells you if repurposing for screenreaders is allowed.
|
public static void encrypt(PdfReader reader, OutputStream os, byte[] userPassword, byte[] ownerPassword, int permissions, boolean strength128Bits) throws DocumentException, IOException
PdfWriter
. 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.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
- true
for 128 bit key length, false
for 40 bit key lengthDocumentException
- on errorIOException
- on errorpublic static void encrypt(PdfReader reader, OutputStream os, byte[] userPassword, byte[] ownerPassword, int permissions, boolean strength128Bits, Map<String,String> newInfo) throws DocumentException, IOException
PdfWriter
. 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.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
- true
for 128 bit key length, false
for 40 bit key lengthnewInfo
- an optional String
map to add or change
the info dictionary. Entries with null
values delete the key in the original info dictionaryDocumentException
- on errorIOException
- on errorpublic static void encrypt(PdfReader reader, OutputStream os, boolean strength, String userPassword, String ownerPassword, int permissions) throws DocumentException, IOException
PdfWriter
. 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.reader
- the read PDFos
- the output destinationstrength
- true
for 128 bit key length, false
for 40 bit key lengthuserPassword
- the user password. Can be null or emptyownerPassword
- the owner password. Can be null or emptypermissions
- the user permissionsDocumentException
- on errorIOException
- on errorpublic static void encrypt(PdfReader reader, OutputStream os, boolean strength, String userPassword, String ownerPassword, int permissions, Map<String,String> newInfo) throws DocumentException, IOException
PdfWriter
. 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.reader
- the read PDFos
- the output destinationstrength
- true
for 128 bit key length, false
for 40 bit key lengthuserPassword
- the user password. Can be null or emptyownerPassword
- the owner password. Can be null or emptypermissions
- the user permissionsnewInfo
- an optional String
map to add or change
the info dictionary. Entries with null
values delete the key in the original info dictionaryDocumentException
- on errorIOException
- on errorpublic static void encrypt(PdfReader reader, OutputStream os, int type, String userPassword, String ownerPassword, int permissions, Map<String,String> newInfo) throws DocumentException, IOException
PdfWriter
. 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.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 optional String
map to add or change
the info dictionary. Entries with null
values delete the key in the original info dictionaryDocumentException
- on errorIOException
- on errorpublic static void encrypt(PdfReader reader, OutputStream os, int type, String userPassword, String ownerPassword, int permissions) throws DocumentException, IOException
PdfWriter
. 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.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 dictionaryDocumentException
- on errorIOException
- on errorpublic static String getPermissionsVerbose(int permissions)
permissions
- the permissions value of a PDF filepublic static boolean isPrintingAllowed(int permissions)
permissions
- the permissions value of a PDF filepublic static boolean isModifyContentsAllowed(int permissions)
permissions
- the permissions value of a PDF filepublic static boolean isCopyAllowed(int permissions)
permissions
- the permissions value of a PDF filepublic static boolean isModifyAnnotationsAllowed(int permissions)
permissions
- the permissions value of a PDF filepublic static boolean isFillInAllowed(int permissions)
permissions
- the permissions value of a PDF filepublic static boolean isScreenReadersAllowed(int permissions)
permissions
- the permissions value of a PDF filepublic static boolean isAssemblyAllowed(int permissions)
permissions
- the permissions value of a PDF filepublic static boolean isDegradedPrintingAllowed(int permissions)
permissions
- the permissions value of a PDF fileCopyright © 2020. All rights reserved.