Skip to main content
All docs
V25.2
  • EncryptionOptions(String, String) Constructor

    Initializes a new instance of the EncryptionOptions class with specified settings.

    Namespace: DevExpress.Docs.Pdf

    Assembly: DevExpress.Docs.Core.v25.2.dll

    Declaration

    public EncryptionOptions(
        string ownerPassword,
        string userPassword
    )

    Parameters

    Name Type Description
    ownerPassword String

    The password that grants full access to the document and allows you to modify security settings. If you do not specify this parameter, an exception is thrown.

    userPassword String

    The password that grants limited access according to the document’s permission settings.

    Example

    The following example protects a PDF document using both the owner and user passwords.

    View Example

    using DevExpress.Pdf;
    
    using (PdfDocumentProcessor pdfDocumentProcessor = new PdfDocumentProcessor()) {
        // Load a PDF document.
        pdfDocumentProcessor.LoadDocument(@"..\..\Demo.pdf");
    
        // Initialize encryption options with owner and user passwords.
        PdfEncryptionOptions encryptionOptions = new PdfEncryptionOptions(
            ownerPassword: "OwnerPassword",
            userPassword: "UserPassword"
        );
    
        // Specify printing, data extraction, modification, and interactivity permissions.
        encryptionOptions.PrintingPermissions = PdfDocumentPrintingPermissions.Allowed;
        encryptionOptions.DataExtractionPermissions = PdfDocumentDataExtractionPermissions.NotAllowed;
        encryptionOptions.ModificationPermissions = PdfDocumentModificationPermissions.DocumentAssembling;
        encryptionOptions.InteractivityPermissions = PdfDocumentInteractivityPermissions.Allowed;
    
        // Specify the 256-bit AES encryption algorithm.
        encryptionOptions.Algorithm = PdfEncryptionAlgorithm.AES256;
    
        // Save the protected document with encryption settings.
        pdfDocumentProcessor.SaveDocument(
            @"..\..\ProtectedDocument.pdf",
            new PdfSaveOptions() { EncryptionOptions = encryptionOptions }
        );
    }
    
    See Also