Hello,
Thanks for your inquiry.
In order to optimize this functionality, we have made an improvement, and the latest version currently uses the following code.
Encrypt document:
- Code: Select all
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(@"in.pdf");
//Create password security policy
PdfSecurityPolicy securityPolicy = new PdfPasswordSecurityPolicy(userPassword, ownerPassword);
//Set encryption algorithm
securityPolicy.EncryptionAlgorithm = PdfEncryptionAlgorithm.AES_128;
//Set document permissions (ownership), do not set default to ForbidAll
securityPolicy.DocumentPrivilege = PdfDocumentPrivilege.AllowAll;
//Set printing permissions
securityPolicy.DocumentPrivilege.AllowPrint = false;
doc.Encrypt(securityPolicy);
doc.SaveToFile(@"out.pdf");
Decrypt document:
- Code: Select all
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(@"in.pdf", ownerPassword);
doc.Decrypt();
doc.SaveToFile(@"out.pdf");
The method you used will be removed in the future, now we recommend using the new interface to implement document encryption and decryption(from 9.7.14). If there is any other issues, please feel free to provide feedback.
Sincerely,
Amin
E-iceblue support team