Home  Products  Purchase  Downloads  Demos  Forums  Blogs  Ticket  Wiki  API  Corporate

com.aspose.pdf.kit
Class PdfFileSecurity

java.lang.Object
  extended bycom.aspose.pdf.kit.PdfFileSecurity

public class PdfFileSecurity
extends java.lang.Object

Represents a class for encrypting or decrypting a Pdf file with owner's or user's password, the owner can change the security setting.


Constructor Summary
PdfFileSecurity(java.io.InputStream inputStream, java.io.OutputStream outputStream)
          Initializes an object instance of PdfFileSecurity.
PdfFileSecurity(java.lang.String inputFile, java.lang.String outputFile)
          Initializes an object instance of PdfFileSecurity.
 
Method Summary
 boolean changePassword(java.lang.String ownerPassword, java.lang.String newUserPassword, java.lang.String newOwnerPassword)
          Changes the user password or owner password by owner, keeps the original security settings.
 boolean changePassword(java.lang.String ownerPassword, java.lang.String newUserPassword, java.lang.String newOwnerPassword, int privilege, boolean b128Bits)
          Changes the user password or password by owner, allows to reset Pdf documnent security.
 boolean decryptFile(java.lang.String ownerPassword)
          Decrypts an encrypted Pdf document by owner.
 boolean encryptFile(java.lang.String userPassword, java.lang.String ownerPassword, int privilege, boolean b128Bits)
          Encrypts Pdf file with userpassword and ownerpassword, sets privileges to access.
 boolean setPrivilege(int privilege)
          Sets Pdf file security involving assemblying,copying,modifying etc.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PdfFileSecurity

public PdfFileSecurity(java.lang.String inputFile,
                       java.lang.String outputFile)
Initializes an object instance of PdfFileSecurity.

Parameters:
inputFile - String Source input Pdf file.
outputFile - String Output Pdf file.

PdfFileSecurity

public PdfFileSecurity(java.io.InputStream inputStream,
                       java.io.OutputStream outputStream)
Initializes an object instance of PdfFileSecurity.

Parameters:
inputStream - InputStream Input Pdf Stream.
outputStream - OutputStream Output Pdf Stream.
Method Detail

changePassword

public boolean changePassword(java.lang.String ownerPassword,
                              java.lang.String newUserPassword,
                              java.lang.String newOwnerPassword)
                       throws java.io.IOException,
                              PdfKitException
Changes the user password or owner password by owner, keeps the original security settings.

Parameters:
ownerPassword - String The owner's password.
newUserPassword - String New user's password.
newOwnerPassword - String New owner's password.
Returns:
boolean - True for success,or false.
Throws:
java.io.IOException
PdfKitException

changePassword

public boolean changePassword(java.lang.String ownerPassword,
                              java.lang.String newUserPassword,
                              java.lang.String newOwnerPassword,
                              int privilege,
                              boolean b128Bits)
                       throws java.io.IOException,
                              PdfKitException
Changes the user password or password by owner, allows to reset Pdf documnent security.

 [SampleCode]
 String inFile = "example1.pdf";
 String outFile = "kitOut.pdf";
 PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile, outFile);
 fileSecurity.changePassword("ownerpass", "user", "owner",PdfPrivilege.Copy | PdfPrivilege.Print, true);
 

Parameters:
ownerPassword - String Owner's password.
newUserPassword - String New user's password.
newOwnerPassword - String New owner's password.
privilege - int Reset security.
b128Bits - boolean Be 128bits encryption.
Returns:
boolean - True for success, or false.
Throws:
java.io.IOException
PdfKitException

encryptFile

public boolean encryptFile(java.lang.String userPassword,
                           java.lang.String ownerPassword,
                           int privilege,
                           boolean b128Bits)
                    throws java.io.IOException,
                           PdfKitException
Encrypts Pdf file with userpassword and ownerpassword, sets privileges to access.

 [SampleCode]
 String inFile = "example1.pdf";
 String outFile = "kitOut.pdf";
 PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile, outFile);
 fileSecurity.encryptFile("userpass", "ownerpass",PdfPrivilege.AllowAll, false);
 

Parameters:
userPassword - String User's password.
ownerPassword - String Ownen's password.
privilege - int Set privilege.
b128Bits - boolean Be 128 bits encryption.
Returns:
boolean True for success, or false.
Throws:
java.io.IOException
PdfKitException

setPrivilege

public boolean setPrivilege(int privilege)
                     throws PdfKitException,
                            java.io.IOException
Sets Pdf file security involving assemblying,copying,modifying etc.

 [SampleCode]
 String inFile = "example1.pdf";
 String outFile = "kitOut.pdf";
 PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile, outFile);
 fileSecurity.setPrivilege(PdfPrivilege.Assembly |PdfPrivilege.ScreenReaders);
 

Parameters:
privilege - int Setting privilege.
Returns:
boolean True for success, or false.
Throws:
PdfKitException
java.io.IOException
See Also:
PdfPrivilege

decryptFile

public boolean decryptFile(java.lang.String ownerPassword)
                    throws java.io.IOException,
                           PdfKitException
Decrypts an encrypted Pdf document by owner.

 [SampleCode]
 String inFile = "example1.pdf";
 String outFile = "kitOut.pdf";
 PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile, outFile);
 fileSecurity.decryptFile("ownerpass");
 

Parameters:
ownerPassword - String Owner's password.
Returns:
boolean True for success,or false.
Throws:
java.io.IOException
PdfKitException