Pdf Security | |
Select.Pdf can be used to set the basic security settings for the generated pdf files and also manage different permissions:
Owner Password
User Password
Assemble Document permission
Copy Content permission
Edit Annotations permission
Edit Content permission
Fill Form Fields permission
Print permission
This can be done using Security property of the PdfDocument object.
The strength of the encryption is set with KeySize and Algorithm. The supported combinations are:
RC4 with a 40-bit or 128-bit key (EncryptKey40Bit, EncryptKey128Bit). Broken; for old viewers only.
AES with a 128-bit or 256-bit key (AES with EncryptKey128Bit or EncryptKey256Bit).
AES-256 revision 6 (EncryptKey256BitRevision6), the AES-256 handler defined by PDF 2.0. This is the default: setting a password is enough.
AES-256-GCM (AESGCM), also defined by PDF 2.0. Choosing it writes the document as PDF 2.0, which older viewers may not open.
A combination that does not exist is adjusted to the nearest one that does: asking for AES with a 40-bit key uses a 128-bit key, and asking for a 256-bit key with RC4 uses AES. The setting that was changed last is kept.
EncryptMetadata set to false leaves the XMP metadata packet readable while the content is encrypted. See Encrypting Regulated Data.
// set document passwords doc.Security.OwnerPassword = "test1"; doc.Security.UserPassword = "test2"; // set the encryption: AES with a 256-bit key doc.Security.KeySize = PdfEncryptionKeySize.EncryptKey256Bit; doc.Security.Algorithm = PdfEncryptionAlgorithm.AES; //set document permissions doc.Security.CanAssembleDocument = false; doc.Security.CanCopyContent = true; doc.Security.CanEditAnnotations = true; doc.Security.CanEditContent = true; doc.Security.CanFillFormFields = true; doc.Security.CanPrint = true;