Protect PDF document
Leave feedback
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 setDocumentOpenPassword() property if password is required to open PDF document;
- Set setPermissionsPassword() property if it is required to change restrictions applied to PDF document;
- Set setPermissions() property to specify exact permissions that should be applied to document;
- Instantiate the PdfViewOptions object and specify saving path format for rendered document.
- Initialize setSecurity() 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.
try (Viewer viewer = new Viewer("sample.docx")) {
Security security = new Security();
security.setDocumentOpenPassword("o123");
security.setPermissionsPassword("p123");
security.setPermissions(Permissions.ALLOW_ALL ^ Permissions.DENY_PRINTING);
PdfViewOptions viewOptions = new PdfViewOptions(filePath);
viewOptions.setSecurity(security);
viewer.view(viewOptions);
}
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.