PDFKit.NET 4.0
Manipulate PDF Security

The following code sample shows how to add security settings to a PDF document. These security settings include a password, AES 256 bit encryption and the restriction of user privileges.

C# code sample using ( FileStream inFile = new FileStream( @"..\..\..\inputDocuments\PackingLightBrochure.pdf", FileMode.Open, FileAccess.Read ) ) { // open the source document Document document = new Document( inFile ); // add new security settings PasswordSecurity passwordSecurity = new PasswordSecurity(); document.Security = passwordSecurity; passwordSecurity.UserPassword = "user"; passwordSecurity.OwnerPassword = "owner"; passwordSecurity.EncryptionLevel = EncryptionLevel.AES_256bit; //NOTICE: for AES_256bit Acrobat 9 (or higher) is required to view!!! passwordSecurity.Print = false; // disable print privilege for users passwordSecurity.CopyExtract = false; // disable copy privilege for user // write the modified document to disk using ( FileStream outFile = new FileStream( @"..\..\addsecuritysettings.pdf", FileMode.Create, FileAccess.Write ) ) { document.Write( outFile ); } }


VB.NET code sample ' add new security settings Dim passwordSecurity As New PasswordSecurity() document.Security = passwordSecurity passwordSecurity.UserPassword = "user" passwordSecurity.OwnerPassword = "owner" passwordSecurity.EncryptionLevel = EncryptionLevel.AES_256bit 'NOTICE: for AES_256bit Acrobat 9 (or higher) is required to view!!! passwordSecurity.Print = False ' disable print privilege passwordSecurity.CopyExtract = False ' disable copy privilege ' write the modified document to disk Using outFile As New FileStream("..\..\addsecuritysettings.pdf", FileMode.Create, FileAccess.Write) document.Write(outFile) End Using

End Using ]]>

When the user tries to open the document, the following pop-up is shown: