officefileapi-devexpress-dot-pdf-0e958a73.md
Contains settings to protect a PDF document with a password and user permissions.
Namespace : DevExpress.Pdf
Assembly : DevExpress.Pdf.v25.2.Core.dll
NuGet Package : DevExpress.Pdf.Core
public class PdfEncryptionOptions
Public Class PdfEncryptionOptions
The following members return PdfEncryptionOptions objects:
To restrict the user from data extraction, data modification, interactive, or printing operations with a PDF document, create a PdfEncryptionOptions object and specify corresponding permissions using PdfEncryptionOptions.DataExtractionPermissions, PdfEncryptionOptions.ModificationPermissions, PdfEncryptionOptions.InteractivityPermissions, and PdfEncryptionOptions.PrintingPermissions properties.
To allow a user to have full access to a document, specify the owner password using the PdfEncryptionOptions.OwnerPasswordString property.
In addition, the user password can be specified using the PdfEncryptionOptions.UserPasswordString property to restrict opening the document.
To specify an encryption algorithm, use the PdfEncryptionOptions.Algorithm property.
To encrypt the document with the specified settings, call the PdfDocumentProcessor.CreateEmptyDocument or PdfDocumentProcessor.SaveDocument overloaded method and pass the PdfSaveOptions object containing these settings as a parameter.
This example shows how a PDF document can be protected using both the owner and user passwords.
Refer to the following topic for more information: Document Protection
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");
// 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 }
);
}
}
}
}
Imports DevExpress.Pdf
Module PDFPasswordProtection
Sub Main()
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
End Sub
End Module
Object PdfEncryptionOptions
See Also