It is possible to set / update permissions and passwords in a PDF document using several of Qoppa’s Java PDF libraries and components.

Call to change document permissions and passwords depending on which Qoppa library you use:

 
// with jPDFSecure
PDFSecure.setPasswordPermissions(newPermPwd, newOpenPwd, permissions, currentPermPwd, encryptType);
 
// with jPDFProcess
PDFDocument.setPasswordPermissions(newPermPwd, newOpenPwd, permissions, currentPermPwd, encryptType);
 
// with jPDFEditor
PDFEditorBean.getDocument().setPasswordPermissions(newPermPwd, newOpenPwd, permissions, currentPermPwd, encryptType);

The parameters are as follow:

  • newPermissionsPwd – This will become the new permissions password.
  • newOpenPwd – This will become the new open password.
  • permissions – A PasswordPermissions object.
  • currentPermissionsPwd – This current permissions password if the PDF document already has a permissions password.
  • encryptType – The encryption type to use: PasswordPermissions.ENCRYPTION_RC4_128, PasswordPermissions.ENCRYPTION_AES_128, PasswordPermissions.ENCRYPTION_AES_256, etc..

Here is sample Java code using jPDFSecure using the class PasswordPermissions:

// Load the document
PDFSecure pdfSecure = new PDFSecure ("input.pdf", null);
// Create permissions object disallowing all permissions
PasswordPermissions perms = new PasswordPermissions (false);
// allow printing
perms.setPrintAllowed(true);
// Set new password permissions
pdfSecure.setPasswordPermissions("owner", "user", perms, currentPermPwd, PasswordPermissions.ENCRYPTION_AES_128);
// Save PDF document (outputPDFFile is a Java File Object) 
pdfSecure.saveDocument("output.pdf");

The permissions that can be set are the following (notice that there is some hierarchy in the permissions):

  • setAssembleDocumentAllowed(boolean allowed)
    Sets the permission to assemble the document. If the permission to Change Document is on then Assemble Document is automatically on.
  • setChangeDocumentAllowed(boolean allowed)
    Sets the permission to change the document.
  • setExtractTextGraphicsAllowed(boolean allowed)
    Sets the permission to extract text and graphics.
  • setExtractTextGraphicsForAccessibilityAllowed(boolean allowed)
    Sets the permission to extract text and graphics in support of accessibility to disabled users or other purposes. If the permissions to Extract Text and Graphics is on then the permission to Extract Text and Graphics for Accessibility is automatically on.
  • setFillFormFieldsAllowed(boolean allowed)
    Sets the permission to fill form fields and sign the document. If the permission to Change Document is on OR the permission to Modify Annots is on then Fill Form Fields is automatically on.
  • setModifyAnnotsAllowed(boolean allowed)
    Sets the permission to add or modify annotations in the document. If the permission to Change Document is on then Modify Annotations is automatically on.
  • setPrintAllowed(boolean allowed)
    Sets the permission to print the document.
  • setPrintHighResAllowed(boolean allowed)
    Sets the permission to print the document at high resolution. If the permissions to Print High Res is on then the permission to Print is automatically on.