PDF Viewer - Protect PDF document
GroupDocs.Viewer enables you to protect PDF document by setting permissions, password for opening and password for changing permissions.
The following steps are to be followed in order to set PDF document permissions.
- Create a new instance of the Viewer class and pass the source document path as a constructor parameter.
- Initialize the instance of Security class;
- Set DocumentOpenPassword property if password is required to open PDF document;
- Set PermissionsPassword property if it is required to change restrictions applied to PDF document;
- Set Permissions property to specify exact permissions that should be applied to document;
- Instantiate the PdfViewOptions object and specify saving path format for rendered document.
- Initialize Security property of PdfViewOptions with object created at previous steps;
- Pass PdfViewOptions object to View method of Viewer class.
Following example demonstrates how to protect output PDF document.
using (Viewer viewer = new Viewer("sample.docx"))
{
Security security = new Security();
security.DocumentOpenPassword = "o123";
security.PermissionsPassword = "p123";
security.Permissions = Permissions.AllowAll ^ Permissions.DenyPrinting;
PdfViewOptions viewOptions = new PdfViewOptions(filePath);
viewOptions.Security = security;
viewer.View(viewOptions);
}
More resources
Advanced Usage Topics
To learn more about document viewing features, please refer to the advanced usage section.
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples:
- GroupDocs.Viewer for .NET examples, plugins, and showcase
- GroupDocs.Viewer for Java examples, plugins, and showcase
- Document Viewer for .NET MVC UI Example
- Document Viewer for .NET App WebForms UI Modern Example
- Document Viewer for Java App Dropwizard UI Modern Example
- Document Viewer for Java Spring UI Example
Free Online App
Along with full-featured .NET library we provide simple but powerful free Apps. You are welcome to view Word, PDF, Excel, PowerPoint documents with free to use online GroupDocs Viewer App.