Protect PDF

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;

© Aspose Pty Ltd 2001-2022. All Rights Reserved.