Secure PDF Documents

Contents
[ ]

Aspose.Cells provides PdfSecurityOptions for working with security. You can set owner and user passwords while saving to PDF. The owner password or user password will be required to open the encrypted PDF document for viewing.

  • The user password can be null or empty string, in this case no password will be required from the user when opening the PDF document.
  • Opening the PDF document with the correct owner password allows full access(without any access restrictions specified) to the document.
  • Opening the PDF document with the correct user password (or opening a document that does not have a user password) allows limited access as the permissions specified.

The sample code below describes how to create secured PDF files with Aspose.Cells for Java API.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SecurePDFDocuments.class);
// Open an Excel file
Workbook workbook = new Workbook(dataDir + "input.xlsx");
// Instantiate PDFSaveOptions to manage security attributes
PdfSaveOptions saveOption = new PdfSaveOptions();
saveOption.setSecurityOptions(new PdfSecurityOptions());
// Set the user password
saveOption.getSecurityOptions().setUserPassword("user");
// Set the owner password
saveOption.getSecurityOptions().setOwnerPassword("owner");
// Disable extracting content permission
saveOption.getSecurityOptions().setExtractContentPermission(false);
// Disable print permission
saveOption.getSecurityOptions().setPrintPermission(false);
// Save the PDF document with encrypted settings
workbook.save(dataDir + "securepdf_test.pdf", saveOption);