Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

PdfSaveOptions.EncryptionOptions Property

Specifies encryption options of a PDF document.

Namespace: DevExpress.Pdf

Assembly: DevExpress.Pdf.v24.2.Core.dll

NuGet Package: DevExpress.Pdf.Core

#Declaration

public PdfEncryptionOptions EncryptionOptions { get; set; }

#Property Value

Type Description
PdfEncryptionOptions

A PdfEncryptionOptions object that represents encryption options of a PDF document.

#Remarks

To protect document opening, create a PdfEncryptionOptions object using the PdfSaveOptions.EncryptionOptions property and specify the user password using the PdfEncryptionOptions.UserPasswordString property.

To restrict the user from data extraction, data modification, interactive, or printing operations with a PDF document, create a PdfEncryptionOptions object using the PdfSaveOptions.EncryptionOptions property and specify the owner password using the PdfEncryptionOptions.OwnerPasswordString property and corresponding permissions using the PdfEncryptionOptions.DataExtractionPermissions, PdfEncryptionOptions.ModificationPermissions,PdfEncryptionOptions.InteractivityPermissions, and PdfEncryptionOptions.PrintingPermissions properties.

For more information, see the Document Protection topic.

#Example

This example shows how a PDF document can be protected using both the owner and user passwords.

Refer to the following topic fro more information: Document Protection

View Example

using DevExpress.Pdf;

namespace PDFPasswordProtection
{
  class Program
  {
    static void Main(string[] args)
    {

      using (PdfDocumentProcessor pdfDocumentProcessor = new PdfDocumentProcessor()) {

        // Load a PDF document.
        pdfDocumentProcessor.LoadDocument("..\\..\\Demo.pdf");

        // Specify printing, data extraction, modification, and interactivity permissions. 
        PdfEncryptionOptions encryptionOptions = new PdfEncryptionOptions();
        encryptionOptions.PrintingPermissions = PdfDocumentPrintingPermissions.Allowed;
        encryptionOptions.DataExtractionPermissions = PdfDocumentDataExtractionPermissions.NotAllowed;
        encryptionOptions.ModificationPermissions = PdfDocumentModificationPermissions.DocumentAssembling;
        encryptionOptions.InteractivityPermissions = PdfDocumentInteractivityPermissions.Allowed;

        // Specify the owner and user passwords for the document.  
        encryptionOptions.OwnerPasswordString = "OwnerPassword";
        encryptionOptions.UserPasswordString = "UserPassword";

        // 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