Skip to main content

EncryptionOptions Class

Contains PDF file encryption settings.

Declaration

public class EncryptionOptions extends JavaObject

Remarks

Create an EncryptionOptions object, configure permissions, and pass the configured object to the PdfDocument.encrypt() method to encrypt the PDF document.

The following code snippet loads a PDF document, encrypts it, restricts specific operations, and saves the result:

import com.devexpress.docs.pdf.*;

import java.nio.file.*;
import java.nio.channels.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try (FileChannel channel = FileChannel.open(Path.of("Document.pdf"));
             PdfDocument pdfDocument = new PdfDocument(channel)) {

            EncryptionOptions encryptionOptions = new EncryptionOptions(
                    "ownerPassword", 
                    "userPassword"
            ) {{

                    setDataExtractionPermissions(DocumentDataExtractionPermissions.NOT_ALLOWED);
                    setPrintPermissions(DocumentPrintPermissions.LOW_QUALITY);
                    setModificationPermissions(DocumentModificationPermissions.NOT_ALLOWED);
                    setAlgorithm(EncryptionAlgorithm.AES_256);
                }};

            pdfDocument.encrypt(encryptionOptions);

            // Save the encrypted document.
            try (WritableByteChannel writableByteChannel =
                 FileChannel.open(Path.of("Document_encrypted.pdf"),
                     StandardOpenOption.CREATE,
                     StandardOpenOption.WRITE,
                     StandardOpenOption.TRUNCATE_EXISTING)) {

                pdfDocument.save(writableByteChannel);
            }
        }
    }
}

Refer to the following help topic for additional information: Encrypt PDF Documents.

Inherited Members

com.devexpress.system.JavaObject.clone()
com.devexpress.system.JavaObject.equals(java.lang.Object)
com.devexpress.system.JavaObject.hashCode()
com.devexpress.system.JavaObject.initFields()
com.devexpress.system.JavaObject.memberwiseClone()
com.devexpress.system.JavaObject.toString()
java.lang.Object.finalize()
java.lang.Object.getClass()
java.lang.Object.notify()
java.lang.Object.notifyAll()
java.lang.Object.wait()
java.lang.Object.wait(long)
java.lang.Object.wait(long,int)

Inheritance

Object
com.devexpress.system.JavaObject
EncryptionOptions

EncryptionOptions(String ownerPassword, String userPassword)

Initializes a new instance of the EncryptionOptions class with specified owner and user passwords.

Declaration

public EncryptionOptions(String ownerPassword, String userPassword)

Parameters

Name Type Description
ownerPassword String

The owner password.

userPassword String

The user password.

Methods

getAlgorithm() Method

Returns an algorithm used to encrypt a PDF file.

Declaration

public EncryptionAlgorithm getAlgorithm()

Returns

Type Description
EncryptionAlgorithm

The encryption algorithm used for the PDF file.

getDataExtractionPermissions() Method

Returns permissions for extracting content from the document.

Declaration

public DocumentDataExtractionPermissions getDataExtractionPermissions()

Returns

Type Description
DocumentDataExtractionPermissions

The data extraction permission level.

getInteractivityPermissions() Method

Returns permissions for document interaction operations.

Declaration

public DocumentInteractivityPermissions getInteractivityPermissions()

Returns

Type Description
DocumentInteractivityPermissions

The document interaction permission level.

getModificationPermissions() Method

Returns permissions for document modification operations.

Declaration

public DocumentModificationPermissions getModificationPermissions()

Returns

Type Description
DocumentModificationPermissions

The document modification permission level.

getOwnerPassword() Method

Returns the owner password.

Declaration

public String getOwnerPassword()

Returns

Type Description
String

The owner password.

getPrintPermissions() Method

Returns permissions for document printing operations.

Declaration

public DocumentPrintPermissions getPrintPermissions()

Returns

Type Description
DocumentPrintPermissions

The document printing permission level.

getUserPassword() Method

Returns the user password.

Declaration

public String getUserPassword()

Returns

Type Description
String

The user password.

setAlgorithm(EncryptionAlgorithm value) Method

Sets an algorithm used to encrypt a PDF file.

Declaration

public void setAlgorithm(EncryptionAlgorithm value)

Parameters

Name Type Description
value EncryptionAlgorithm

The encryption algorithm used for the PDF file.

setDataExtractionPermissions(DocumentDataExtractionPermissions value) Method

Sets permissions for extracting content from the document.

Declaration

public void setDataExtractionPermissions(DocumentDataExtractionPermissions value)

Parameters

Name Type Description
value DocumentDataExtractionPermissions

The data extraction permission level.

setInteractivityPermissions(DocumentInteractivityPermissions value) Method

Sets permissions for document interaction operations.

Declaration

public void setInteractivityPermissions(DocumentInteractivityPermissions value)

Parameters

Name Type Description
value DocumentInteractivityPermissions

The document interaction permission level.

setModificationPermissions(DocumentModificationPermissions value) Method

Sets permissions for document modification operations.

Declaration

public void setModificationPermissions(DocumentModificationPermissions value)

Parameters

Name Type Description
value DocumentModificationPermissions

The document modification permission level.

setPrintPermissions(DocumentPrintPermissions value) Method

Sets permissions for document printing operations.

Declaration

public void setPrintPermissions(DocumentPrintPermissions value)

Parameters

Name Type Description
value DocumentPrintPermissions

The document printing permission level.