Skip to main content
All docs
V26.1
  • EncryptionOptions Class

    Contains members used to specify encryption options a PDF file.

    Namespace: DevExpress.Docs.Pdf

    Assembly: DevExpress.Docs.Core.v26.1.dll

    Declaration

    public class EncryptionOptions

    The following members return EncryptionOptions objects:

    Remarks

    The EncryptionOptions property allows you to obtain and specify the security options of the exported PDF file.

    User and Owner Passwords

    The UserPassword parameter of the EncryptionOptions constructor allows you to specify the user password. This password is used when you want to prevent unauthorized access to a document and protect sensitive information.

    The OwnerPassword parameter of the EncryptionOptions constructor specifies the permission (or owner) password used to restrict operations in the PDF document.

    Note

    If the Owner and User passwords are the same or the Owner password is missing and the document is protected only with the User password, the resulting document has a document opening restriction. In this case, any user has full access to this document after opening it.

    Restrict Document Operations

    Use the following options to restrict data extraction, data modification, interactive, or printing operations:

    To apply restrictions, create the EncryptionOptions instance and pass it to the EncryptionOptions property. Users need to enter the owner’s password when opening a document to gain full access.

    Examples

    How to: Encrypt a Presentation Exported to PDF

    The following code snippet specifies available encryption settings:

    using DevExpress.Docs.Pdf;
    using DevExpress.Docs.Presentation;
    using DevExpress.Docs.Presentation.Export;
    using System.IO;
    
    using (var presentation = new Presentation(File.ReadAllBytes(@"C:\Documents\Presentation.pptx"))) {
        var options = new PdfExportOptions();
    
        // Initialize encryption options with owner and user passwords:
        options.EncryptionOptions = new EncryptionOptions(
            ownerPassword: "ownerPassword",
            userPassword: "userPassword"
        );
    
        // Specify operation restrictions:
        options.EncryptionOptions.DataExtractionPermissions =
            DocumentDataExtractionPermissions.NotAllowed;
        options.EncryptionOptions.PrintPermissions =
            DocumentPrintPermissions.LowQuality;
        options.EncryptionOptions.ModificationPermissions =
            DocumentModificationPermissions.NotAllowed;
    
        // Specify encryption algorithm:
        options.EncryptionOptions.Algorithm = EncryptionAlgorithm.AES256;
    
        presentation.ExportToPdf(
            new FileStream(@"C:\Documents\Presentation.pdf", FileMode.Create, FileAccess.ReadWrite),
            options
        );
    }
    

    How to: Encrypt a PDF Document

    The following example sets permissions and encrypts a PDF document with the user and owner passwords.

    using DevExpress.Docs.Pdf;
    using System.IO;
    
    using (FileStream fileStream = File.OpenRead(@"C:\Test Documents\Document.pdf"))
    {
        using (PdfDocument pdfDocument = new PdfDocument(fileStream, new LoadOptions { Password = "your_password_here" }))
        {
            var encryptionOptions = new EncryptionOptions(
                ownerPassword: "ownerPassword",
                userPassword: "userPassword"
            );
    
            encryptionOptions.DataExtractionPermissions =
                DocumentDataExtractionPermissions.NotAllowed;
            encryptionOptions.PrintPermissions =
                DocumentPrintPermissions.LowQuality;
            encryptionOptions.ModificationPermissions =
                DocumentModificationPermissions.NotAllowed;
            encryptionOptions.Algorithm = EncryptionAlgorithm.AES256;
    
            pdfDocument.Encrypt(encryptionOptions);
            pdfDocument.Save(
                new FileStream(@"C:\Test Documents\Document_upd.pdf", FileMode.Create, FileAccess.Write));
        }
    }
    

    Inheritance

    Object
    EncryptionOptions
    See Also