public class PDFSecure extends Object
PDFSecure
class provides methods to update security settings on a pdf document.
It can encrypt and decrypt a PDF document as well as set permissions on the document.Modifier and Type | Class and Description |
---|---|
static class |
PDFSecure.KeyInfoSecure
This is the Main-Class for the jPDFSecure.jar that can generate server
key requests, validate a key, and display server information.
|
Constructor and Description |
---|
PDFSecure(InputStream inStream,
IPassword password)
Loads a PDF document from an InputStream.
|
PDFSecure(String fileName,
IPassword password)
Loads a PDF document from a file.
|
PDFSecure(URL url,
IPassword password)
Loads a PDF document from a URL.
|
Modifier and Type | Method and Description |
---|---|
SignatureField |
addSignatureField(int pageIndex,
String fieldName,
Rectangle2D bounds)
Adds a signature field to a page in the document.
|
void |
clearPasswordPermissions(String currentPermissionsPwd)
Clears the security for this document.
|
void |
clearSecurity(String currentPermissionsPwd)
Deprecated.
|
void |
clearUsageRights()
Remove extended permissions from the document.
|
void |
close()
Close / release all resources held by this document.
|
DocumentInfo |
getDocumentInfo()
Returns a DocumentInfo object containing the information
section of a PDF document (author, title, etc.)
|
int |
getEncryptionType()
Get the encryption type used to encrypt the document (PasswordPermissions.ENCRYPTION_RC4_128, PasswordPermissions.ENCRYPTION_RC4_128, PasswordPermissions.ENCRYPTION_AES_128, etc...).
|
String |
getPDFFileVersion()
Return the PDF file version for the current document.
|
AllPDFPermissions |
getPDFPermissions()
Returns the AllPDFPermissions object which encompasses this document's PasswordPermissions, DocMDPPermissions, and UsageRightsPermissions.
|
Vector<SignatureField> |
getSignatureFields()
Gets a list of signature fields, if any.
|
static String |
getVersion()
Returns version string for jPDFSecure.
|
boolean |
hasOpenPassword()
Returns a flag indicating whether this document is encrypted with a
'user' password.
|
boolean |
hasPermissionsPassword()
Returns a flag indicating whether this document is encrypted with a
'owner' password.
|
boolean |
isEncrypted()
Returns a flag indicating whether this document is encrypted.
|
static void |
loadLicense(InputStream licenseStream)
Method to load a license file from an inputstream.
|
static void |
loadLicense(String licenseFile)
Method to load a license file.
|
void |
saveDocument(OutputStream outStream)
Saves this document to an output stream.
|
void |
saveDocument(String fileName)
Saves this document to a file.
|
static boolean |
setAppletKey(String key,
Applet applet)
Method to unlock the production version of the library.
|
static boolean |
setKey(String key)
Method to unlock the production version of the library.
|
void |
setPasswordPermissions(String newPermPwd,
String newOpenPwd,
PasswordPermissions permissions,
String currentPermPwd,
int encryptType)
Sets the security for this document.
|
void |
setPDFFileVersion(int majorVersion,
int minorVersion)
Set the PDF file version.
|
void |
setSecurity(String newPermPwd,
String newOpenPwd,
PasswordPermissions permissions,
String currentPermPwd,
int encryptType)
Deprecated.
|
void |
signDocument(SignatureField signField,
SigningInformation signingInfo)
Signs this document using the given signature field.
|
boolean |
usePermissionsPassword(String ownerPassword)
Tells the PDFSecure object that the permissions password is known, so all
permissions are granted.
|
public PDFSecure(String fileName, IPassword password) throws PDFException
fileName
- Name of the PDF file.password
- An object that provides passwords to open the document, leave null if not needed.
When working with documents that have no passwords, the host application should pass null for the
value of this parameter. When documents are known to have passwords, the host application should
pass an instance of the PDFPassword
class that can hold a single
password or a list of passwords.PDFException
- When there is an error loading the document.public PDFSecure(InputStream inStream, IPassword password) throws PDFException
inStream
- InputStream to read the PDF document.password
- An object that provides passwords to open the document, leave null if not needed.
When working with documents that have no passwords, the host application should pass null for the
value of this parameter. When documents are known to have passwords, the host application should
pass an instance of the PDFPassword
class that can hold a single
password or a list of passwords.PDFException
- When there is an error loading the document.public PDFSecure(URL url, IPassword password) throws PDFException
url
- Location of the PDF document.password
- An object that provides passwords to open the document, leave null if not needed.
When working with documents that have no passwords, the host application should pass null for the
value of this parameter. When documents are known to have passwords, the host application should
pass an instance of the PDFPassword
class that can hold a single
password or a list of passwords.PDFException
- When there is an error loading the document.public void close()
public void setSecurity(String newPermPwd, String newOpenPwd, PasswordPermissions permissions, String currentPermPwd, int encryptType) throws PDFException
setPasswordPermissions(String, String, PasswordPermissions, String, int)
instead.newPermPwd
- The document's new permissions password.newOpenPwd
- The document's new open password.permissions
- Permission object.currentPermPwd
- The current permissions password. This parameter is needed if the
document has a permissions password.encryptType
- - The encryption type to use: PDFPermissions.ENCRYPTION_RC4_128, PDFPermissions.ENCRYPTION_RC4_128, PDFPermissions.ENCRYPTION_AES_128, etc...PDFException
public void setPasswordPermissions(String newPermPwd, String newOpenPwd, PasswordPermissions permissions, String currentPermPwd, int encryptType) throws PDFException
newPermPwd
- The document's new permissions password.newOpenPwd
- The document's new open password.permissions
- Permission object.currentPermPwd
- The current permissions password. This parameter is needed if the
document has a permissions password.encryptType
- - The encryption type to use: PasswordPermissions.ENCRYPTION_RC4_128, PasswordPermissions.ENCRYPTION_RC4_128, PasswordPermissions.ENCRYPTION_AES_128, etc...PDFException
- If there is an error setting the password permissions.public boolean hasOpenPassword()
public DocumentInfo getDocumentInfo()
public final AllPDFPermissions getPDFPermissions()
public void clearUsageRights() throws PDFException
PDFException
- If there is an error clearing the usage rights.public boolean hasPermissionsPassword()
public void saveDocument(String fileName) throws IOException, PDFException
fileName
- Name of the file to save the document.IOException
PDFException
public void saveDocument(OutputStream outStream) throws IOException, PDFException
outStream
- OutputStream where the document will be written to.IOException
PDFException
public static boolean setKey(String key)
key
- Production key.public static void loadLicense(InputStream licenseStream) throws LicenseException
licenseStream
- The input stream for the license file contents.LicenseException
- If there are any problems with the license filepublic static void loadLicense(String licenseFile) throws LicenseException, IOException
licenseFile
- The full path to the license file.LicenseException
- If there are any problems with the license fileIOException
public static boolean setAppletKey(String key, Applet applet)
key
- Production key.public static String getVersion()
public boolean isEncrypted()
public void clearSecurity(String currentPermissionsPwd) throws PDFException
currentPermissionsPwd
- The document's current permissions password. This parameter is needed
if the document has a permissions password.PDFException
public void clearPasswordPermissions(String currentPermissionsPwd) throws PDFException
currentPermissionsPwd
- The document's current permissions password. This parameter is needed
if the document has a permissions password.PDFException
public boolean usePermissionsPassword(String ownerPassword) throws PDFException
ownerPassword
- The permissions passwordPDFException
public void signDocument(SignatureField signField, SigningInformation signingInfo) throws PDFException
signField
- The field to use to sign the document.signingInfo
- Information required to sign the document.PDFException
public SignatureField addSignatureField(int pageIndex, String fieldName, Rectangle2D bounds) throws PDFException
PDFSecure.signDocument
.
To create an invisible signature field, the bound rectangle should be set to (0,0,0,0) for the bounds.pageIndex
- The index of the page to add the signature field on.fieldName
- The name of the new field.bounds
- The bounds of the field on the page. (0,0,0,0) indicates that the signature field will be invisible.PDFException
- If there is a problem adding the signature field.public Vector<SignatureField> getSignatureFields()
public int getEncryptionType()
public String getPDFFileVersion()
public void setPDFFileVersion(int majorVersion, int minorVersion)
majorVersion
- The integer part of the versionminorVersion
- The decimal part of the version