Back to Devexpress

EncryptionOptions(String, String) Constructor

officefileapi-devexpress-dot-docs-dot-pdf-dot-encryptionoptions-dot-ctor-x28-system-dot-string-system-dot-string-x29.md

latest4.2 KB
Original Source

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

NuGet Package : DevExpress.Docs.Core

Declaration

csharp
public EncryptionOptions(
    string ownerPassword,
    string userPassword
)
vb
Public Sub New(
    ownerPassword As String,
    userPassword As String
)

Parameters

NameTypeDescription
ownerPasswordString

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

csharp
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 }
    );
}
vb
Imports DevExpress.Pdf

Using pdfDocumentProcessor As New PdfDocumentProcessor()
    ' Load a PDF document.
    pdfDocumentProcessor.LoadDocument("..\..\Demo.pdf")

    ' Initialize encryption options with owner and user passwords.
    Dim encryptionOptions As 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() With {.EncryptionOptions = encryptionOptions}
    )
End Using

See Also

EncryptionOptions Class

EncryptionOptions Members

DevExpress.Docs.Pdf Namespace