com.qoppa.pdfSecure
Class PDFSecure

java.lang.Object
  extended bycom.qoppa.pdfSecure.PDFSecure

public class PDFSecure
extends Object

The 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.

Author:
Qoppa Software

Constructor Summary
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.
 
Method Summary
 SignatureField addSignatureField(int pageIndex, String fieldName, Rectangle2D bounds)
          Adds a signature field to a page in the documnet.
 void clearSecurity(String currentPermissionsPwd)
          Clears the security for this document.
 DocumentInfo getDocumentInfo()
          Returns a DocumentInfo object containing the information section of a PDF document (author, title, etc.)
 PDFPermissions getPermissions()
          Returns the permissions object for this document.
 Vector 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.
 void saveDocument(OutputStream outStream)
          Saves this document to an output stream.
 void saveDocument(String fileName)
          Saves this document to a file.
static void setAppletKey(String key, Applet applet)
          Method to unlock the production version of the library.
static void setKey(String key)
          Method to unlock the production version of the library.
 void setSecurity(String newPermPwd, String newOpenPwd, PDFPermissions permissions, String currentPermPwd, int encryptType)
          Sets the security for this document.
 void signDocument(SignatureField signField, SigningInformation signingInfo)
          Signs this document using the given signature field.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PDFSecure

public PDFSecure(String fileName,
                 IPassword password)
          throws PDFException
Loads a PDF document from a file.

Parameters:
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.

PDFSecure

public PDFSecure(InputStream inStream,
                 IPassword password)
          throws PDFException
Loads a PDF document from an InputStream.

Parameters:
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.

PDFSecure

public PDFSecure(URL url,
                 IPassword password)
          throws PDFException
Loads a PDF document from a URL.

Parameters:
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.
Method Detail

setSecurity

public void setSecurity(String newPermPwd,
                        String newOpenPwd,
                        PDFPermissions permissions,
                        String currentPermPwd,
                        int encryptType)
                 throws PDFException
Sets the security for this document. If the open password is null, the user won't have to enter a password to open the document. If the permissions password is null, any user can change the permissions on the document. The document will be encrypted regardless. To clear the encryption, call the @method clearSecurity method.

Parameters:
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, this value can be either PDFPermissions.ENCRYPTION_RC4 or PDFPermissions.ENCRYPTION_AES.
Throws:
PDFException

hasOpenPassword

public boolean hasOpenPassword()
Returns a flag indicating whether this document is encrypted with a 'user' password.

Returns:
boolean true if the document is encrypted with an open password, false otherwise.

getDocumentInfo

public DocumentInfo getDocumentInfo()
Returns a DocumentInfo object containing the information section of a PDF document (author, title, etc.)

Returns:
DocumentInfo Object containing header information for the document.

getPermissions

public PDFPermissions getPermissions()
Returns the permissions object for this document.

Returns:
Permissions for the document.

hasPermissionsPassword

public boolean hasPermissionsPassword()
Returns a flag indicating whether this document is encrypted with a 'owner' password.

Returns:
boolean true if the document is encrypted with a permissions password, false otherwise.

saveDocument

public void saveDocument(String fileName)
                  throws IOException,
                         PDFException
Saves this document to a file.

Parameters:
fileName - Name of the file to save the document.
Throws:
IOException
PDFException

saveDocument

public void saveDocument(OutputStream outStream)
                  throws IOException,
                         PDFException
Saves this document to an output stream.

Parameters:
outStream - OutputStream where the document will be written to.
Throws:
IOException
PDFException

setKey

public static void setKey(String key)
Method to unlock the production version of the library.

Parameters:
key - Production key.

setAppletKey

public static void setAppletKey(String key,
                                Applet applet)
Method to unlock the production version of the library.

Parameters:
key - Production key.

getVersion

public static String getVersion()
Returns version string for jPDFSecure. If this is the demo version, the return string will contain 'Demo Version' at the end.


isEncrypted

public boolean isEncrypted()
Returns a flag indicating whether this document is encrypted.

Returns:
boolean true if the document is encrypted with a user password, false otherwise.

clearSecurity

public void clearSecurity(String currentPermissionsPwd)
                   throws PDFException
Clears the security for this document. Calling this method will clear user password, owner password, permissions and encryption.

Parameters:
currentPermissionsPwd - The document's current permissions password. This parameter is needed if the document has a permissions password.
Throws:
PDFException

signDocument

public void signDocument(SignatureField signField,
                         SigningInformation signingInfo)
                  throws PDFException
Signs this document using the given signature field.

Parameters:
signField - The field to use to sign the document.
signingInfo - Information required to sign the document.
Throws:
PDFException

addSignatureField

public SignatureField addSignatureField(int pageIndex,
                                        String fieldName,
                                        Rectangle2D bounds)
                                 throws PDFException
Adds a signature field to a page in the documnet. The signature field is added to the page but is NOT signed. To sign the document, the application must call PDFSecure.signDocument. To create an invisible signature field, the bound rectangle should be set to (0,0,0,0) for the bounds.

Parameters:
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.
Throws:
PDFException

getSignatureFields

public Vector getSignatureFields()
Gets a list of signature fields, if any. The list returned contains objects of type SignatureField.

Returns:
List of signature fields (if any) in the AcroForm. If there are no fields, this method returns null.