Add password to PDF with permissions
Leave feedback
You can easy protect PDF document with permissions, using the “GroupDocs.Merger for .NET” product.
The following example demonstrates how to secure PDF document with permissions in C# code:
- Initialize PdfSecurityOptions class with new document password and set Permissions property with enum value of PdfSecurityPermissions;
- Instantiate Merger object with source document path or stream;
- Call AddPassword method and pass PdfSecurityOptions object to it;
- Call Save method specifying file path to save resultant document.
string filePath = @"c:\sample.pdf";
string filePathOut = @"c:\output\result.pdf";
PdfSecurityOptions pdfSecurityOptions = new PdfSecurityOptions("SAMPLE_PASSWORD");
pdfSecurityOptions.Permissions = PdfSecurityPermissions.DenyModification;
using (Merger merger = new Merger(filePath))
{
merger.AddPassword(pdfSecurityOptions);
merger.Save(filePathOut);
}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.