Back to Devexpress

EncryptionOptions Class

officefileapi-devexpress-dot-docs-dot-pdf-196e4d98.md

latest5.2 KB
Original Source

EncryptionOptions Class

Contains members used to specify encryption options of an exported PDF file.

Namespace : DevExpress.Docs.Pdf

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

NuGet Package : DevExpress.Docs.Core

Declaration

csharp
public class EncryptionOptions
vb
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.

Example

The following code snippet specifies available encryption settings:

csharp
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
    );
}
vb
Imports DevExpress.Docs.Pdf
Imports DevExpress.Docs.Presentation
Imports DevExpress.Docs.Presentation.Export
Imports System.IO

Using presentation As New Presentation(File.ReadAllBytes("C:\Documents\Presentation.pptx"))
    Dim options As 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
    )
End Using

Inheritance

Object EncryptionOptions

See Also

EncryptionOptions Members

DevExpress.Docs.Pdf Namespace