安全的 PDF 文档

Contents
[ ]

Aspose.Cells提供了PdfSecurityOptions以处理安全性。您可以在保存为PDF时设置所有者密码和用户密码。打开加密的PDF文档以查看时将需要所有者密码或用户密码。

  • 用户密码可以为null或空字符串,在这种情况下,用户打开PDF文档时将不需要密码。
  • 使用正确的所有者密码打开PDF文档允许对文档进行完全访问(未指定任何访问限制)。
  • 使用正确的用户密码打开PDF文档(或打开没有用户密码的文档)允许进行有限访问,如权限所述。

下面的示例代码描述如何使用 Aspose.Cells for Java API 创建安全的PDF文件。

// 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);