officefileapi-devexpress-dot-docs-dot-pdf-dot-encryptionoptions-dot-ctor-x28-system-dot-string-system-dot-string-x29.md
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
public EncryptionOptions(
string ownerPassword,
string userPassword
)
Public Sub New(
ownerPassword As String,
userPassword As String
)
| 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.
|
The following example protects a PDF document using both the owner and user passwords.
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 }
);
}
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