PdfEncryptionDetails

Inheritance: java.lang.Object

public class PdfEncryptionDetails

Contains details for encrypting and access permissions for a PDF document.

To learn more, visit the Protect or Encrypt a Document documentation article.

Examples:

Shows how to set permissions on a saved PDF document.


 Document doc = new Document();
 DocumentBuilder builder = new DocumentBuilder(doc);

 builder.writeln("Hello world!");

 // Extend permissions to allow the editing of annotations.
 PdfEncryptionDetails encryptionDetails =
         new PdfEncryptionDetails("password", "", PdfPermissions.MODIFY_ANNOTATIONS | PdfPermissions.DOCUMENT_ASSEMBLY);

 // Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
 // to modify how that method converts the document to .PDF.
 PdfSaveOptions saveOptions = new PdfSaveOptions();

 // Enable encryption via the "EncryptionDetails" property.
 saveOptions.setEncryptionDetails(encryptionDetails);

 // When we open this document, we will need to provide the password before accessing its contents.
 doc.save(getArtifactsDir() + "PdfSaveOptions.EncryptionPermissions.pdf", saveOptions);
 

Constructors

ConstructorDescription
PdfEncryptionDetails(String userPassword, String ownerPassword)Initializes an instance of this class.
PdfEncryptionDetails(String userPassword, String ownerPassword, int permissions)Initializes a new instance of this class.

Methods

MethodDescription
getOwnerPassword()Specifies the owner password for the encrypted PDF document.
getPermissions()Specifies the operations that are allowed to a user on an encrypted PDF document.
getUserPassword()Specifies the user password required for opening the encrypted PDF document.
setOwnerPassword(String value)Specifies the owner password for the encrypted PDF document.
setPermissions(int value)Specifies the operations that are allowed to a user on an encrypted PDF document.
setUserPassword(String value)Specifies the user password required for opening the encrypted PDF document.

PdfEncryptionDetails(String userPassword, String ownerPassword)

public PdfEncryptionDetails(String userPassword, String ownerPassword)

Initializes an instance of this class.

Parameters:

ParameterTypeDescription
userPasswordjava.lang.String
ownerPasswordjava.lang.String

PdfEncryptionDetails(String userPassword, String ownerPassword, int permissions)

public PdfEncryptionDetails(String userPassword, String ownerPassword, int permissions)

Initializes a new instance of this class.

Parameters:

ParameterTypeDescription
userPasswordjava.lang.String
ownerPasswordjava.lang.String
permissionsint

getOwnerPassword()

public String getOwnerPassword()

Specifies the owner password for the encrypted PDF document.

Remarks:

The owner password allows the user to open an encrypted PDF document without any access restrictions specified in getPermissions() / setPermissions(int).

The owner password cannot be the same as the user password.

Examples:

Shows how to set permissions on a saved PDF document.


 Document doc = new Document();
 DocumentBuilder builder = new DocumentBuilder(doc);

 builder.writeln("Hello world!");

 // Extend permissions to allow the editing of annotations.
 PdfEncryptionDetails encryptionDetails =
         new PdfEncryptionDetails("password", "", PdfPermissions.MODIFY_ANNOTATIONS | PdfPermissions.DOCUMENT_ASSEMBLY);

 // Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
 // to modify how that method converts the document to .PDF.
 PdfSaveOptions saveOptions = new PdfSaveOptions();

 // Enable encryption via the "EncryptionDetails" property.
 saveOptions.setEncryptionDetails(encryptionDetails);

 // When we open this document, we will need to provide the password before accessing its contents.
 doc.save(getArtifactsDir() + "PdfSaveOptions.EncryptionPermissions.pdf", saveOptions);
 

Returns: java.lang.String - The corresponding java.lang.String value.

getPermissions()

public int getPermissions()

Specifies the operations that are allowed to a user on an encrypted PDF document. The default value is PdfPermissions.DISALLOW_ALL.

Examples:

Shows how to set permissions on a saved PDF document.


 Document doc = new Document();
 DocumentBuilder builder = new DocumentBuilder(doc);

 builder.writeln("Hello world!");

 // Extend permissions to allow the editing of annotations.
 PdfEncryptionDetails encryptionDetails =
         new PdfEncryptionDetails("password", "", PdfPermissions.MODIFY_ANNOTATIONS | PdfPermissions.DOCUMENT_ASSEMBLY);

 // Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
 // to modify how that method converts the document to .PDF.
 PdfSaveOptions saveOptions = new PdfSaveOptions();

 // Enable encryption via the "EncryptionDetails" property.
 saveOptions.setEncryptionDetails(encryptionDetails);

 // When we open this document, we will need to provide the password before accessing its contents.
 doc.save(getArtifactsDir() + "PdfSaveOptions.EncryptionPermissions.pdf", saveOptions);
 

Returns: int - The corresponding int value. The returned value is a bitwise combination of PdfPermissions constants.

getUserPassword()

public String getUserPassword()

Specifies the user password required for opening the encrypted PDF document.

Remarks:

The user password will be required to open an encrypted PDF document for viewing. The permissions specified in getPermissions() / setPermissions(int) will be enforced by the reader software.

The user password can be null or empty string, in this case no password will be required from the user when opening the PDF document. The user password cannot be the same as the owner password.

Examples:

Shows how to set permissions on a saved PDF document.


 Document doc = new Document();
 DocumentBuilder builder = new DocumentBuilder(doc);

 builder.writeln("Hello world!");

 // Extend permissions to allow the editing of annotations.
 PdfEncryptionDetails encryptionDetails =
         new PdfEncryptionDetails("password", "", PdfPermissions.MODIFY_ANNOTATIONS | PdfPermissions.DOCUMENT_ASSEMBLY);

 // Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
 // to modify how that method converts the document to .PDF.
 PdfSaveOptions saveOptions = new PdfSaveOptions();

 // Enable encryption via the "EncryptionDetails" property.
 saveOptions.setEncryptionDetails(encryptionDetails);

 // When we open this document, we will need to provide the password before accessing its contents.
 doc.save(getArtifactsDir() + "PdfSaveOptions.EncryptionPermissions.pdf", saveOptions);
 

Returns: java.lang.String - The corresponding java.lang.String value.

setOwnerPassword(String value)

public void setOwnerPassword(String value)

Specifies the owner password for the encrypted PDF document.

Remarks:

The owner password allows the user to open an encrypted PDF document without any access restrictions specified in getPermissions() / setPermissions(int).

The owner password cannot be the same as the user password.

Examples:

Shows how to set permissions on a saved PDF document.


 Document doc = new Document();
 DocumentBuilder builder = new DocumentBuilder(doc);

 builder.writeln("Hello world!");

 // Extend permissions to allow the editing of annotations.
 PdfEncryptionDetails encryptionDetails =
         new PdfEncryptionDetails("password", "", PdfPermissions.MODIFY_ANNOTATIONS | PdfPermissions.DOCUMENT_ASSEMBLY);

 // Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
 // to modify how that method converts the document to .PDF.
 PdfSaveOptions saveOptions = new PdfSaveOptions();

 // Enable encryption via the "EncryptionDetails" property.
 saveOptions.setEncryptionDetails(encryptionDetails);

 // When we open this document, we will need to provide the password before accessing its contents.
 doc.save(getArtifactsDir() + "PdfSaveOptions.EncryptionPermissions.pdf", saveOptions);
 

Parameters:

ParameterTypeDescription
valuejava.lang.StringThe corresponding java.lang.String value.

setPermissions(int value)

public void setPermissions(int value)

Specifies the operations that are allowed to a user on an encrypted PDF document. The default value is PdfPermissions.DISALLOW_ALL.

Examples:

Shows how to set permissions on a saved PDF document.


 Document doc = new Document();
 DocumentBuilder builder = new DocumentBuilder(doc);

 builder.writeln("Hello world!");

 // Extend permissions to allow the editing of annotations.
 PdfEncryptionDetails encryptionDetails =
         new PdfEncryptionDetails("password", "", PdfPermissions.MODIFY_ANNOTATIONS | PdfPermissions.DOCUMENT_ASSEMBLY);

 // Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
 // to modify how that method converts the document to .PDF.
 PdfSaveOptions saveOptions = new PdfSaveOptions();

 // Enable encryption via the "EncryptionDetails" property.
 saveOptions.setEncryptionDetails(encryptionDetails);

 // When we open this document, we will need to provide the password before accessing its contents.
 doc.save(getArtifactsDir() + "PdfSaveOptions.EncryptionPermissions.pdf", saveOptions);
 

Parameters:

ParameterTypeDescription
valueintThe corresponding int value. The value must be a bitwise combination of PdfPermissions constants.

setUserPassword(String value)

public void setUserPassword(String value)

Specifies the user password required for opening the encrypted PDF document.

Remarks:

The user password will be required to open an encrypted PDF document for viewing. The permissions specified in getPermissions() / setPermissions(int) will be enforced by the reader software.

The user password can be null or empty string, in this case no password will be required from the user when opening the PDF document. The user password cannot be the same as the owner password.

Examples:

Shows how to set permissions on a saved PDF document.


 Document doc = new Document();
 DocumentBuilder builder = new DocumentBuilder(doc);

 builder.writeln("Hello world!");

 // Extend permissions to allow the editing of annotations.
 PdfEncryptionDetails encryptionDetails =
         new PdfEncryptionDetails("password", "", PdfPermissions.MODIFY_ANNOTATIONS | PdfPermissions.DOCUMENT_ASSEMBLY);

 // Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
 // to modify how that method converts the document to .PDF.
 PdfSaveOptions saveOptions = new PdfSaveOptions();

 // Enable encryption via the "EncryptionDetails" property.
 saveOptions.setEncryptionDetails(encryptionDetails);

 // When we open this document, we will need to provide the password before accessing its contents.
 doc.save(getArtifactsDir() + "PdfSaveOptions.EncryptionPermissions.pdf", saveOptions);
 

Parameters:

ParameterTypeDescription
valuejava.lang.StringThe corresponding java.lang.String value.