Click or drag to resize
Pdf Library for .NET

PdfDocumentSecurity Class

Represents the security settings of a PDF document, including passwords, encryption algorithm / key size, and per-operation permissions. Accessed through Security. Encryption is written to the output only when at least one password is set or a permission is restricted; clearing both passwords on a loaded document and saving strips existing encryption.
Inheritance Hierarchy
SystemObject
  SelectPdf.UniversalPdfDocumentSecurity

Namespace: SelectPdf.Universal
Assembly: SelectPdf.Universal (in SelectPdf.Universal.dll) Version: 26.4
Syntax
public class PdfDocumentSecurity

The PdfDocumentSecurity type exposes the following members.

Properties
 NameDescription
Public propertyAlgorithm Gets or sets the encryption algorithm. Defaults to AES for a new document and for a loaded document that is not encrypted. Setting a value that is incompatible with the current KeySize silently adjusts the key size to a supported one (AES + 40-bit → 128-bit; AES-GCM → 256-bit; RC4 + 256-bit → 128-bit).
Public propertyCanAccessibilityCopyContent Gets or sets a value indicating whether content can be copied for accessibility purposes.
Public propertyCanAssembleDocument Gets or sets a value indicating whether the document can be assembled (insert, rotate, or delete pages and create bookmarks or thumbnails).
Public propertyCanCopyContent Gets or sets a value indicating whether the document content can be copied.
Public propertyCanEditAnnotations Gets or sets a value indicating whether annotations can be edited.
Public propertyCanEditContent Gets or sets a value indicating whether the document content can be edited.
Public propertyCanFillFormFields Gets or sets a value indicating whether form fields can be filled.
Public propertyCanPrint Gets or sets a value indicating whether the document can be printed.
Public propertyEncryptMetadata Gets or sets whether the document's XMP metadata stream is encrypted with the rest of the document. The default value is true.
Public propertyKeySize Gets or sets the length of the encryption key. Defaults to EncryptKey256BitRevision6 (AES-256) for a new document and for a loaded document that is not encrypted; an encrypted document keeps its own. Setting a value that is incompatible with the current Algorithm silently adjusts the algorithm to a supported one (40-bit → RC4; 256-bit + RC4 → AES; 256-bit revision 6 → AES). Valid combinations: 40/128-bit + RC4, 128/256-bit + AES, 256-bit revision 6 + AES (PDF 2.0), 256-bit + AES-GCM (PDF 2.0).
Public propertyOwnerPassword Gets or sets the owner password required to change document permissions.
Public propertyUserPassword Gets or sets the user password required to open the document.
Top
Example
PdfDocument document = new PdfDocument();
document.AddPage();
document.Security.UserPassword = "open123";
document.Security.OwnerPassword = "owner456";
document.Security.Algorithm = PdfEncryptionAlgorithm.AES;
document.Security.CanPrint = true;
document.Security.CanCopyContent = false;
document.Save("secured.pdf");
document.Close();
See Also