安全的 PDF 文档

Contents
[ ]

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

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

下面的示例代码描述了如何使用Aspose.Cells保护PDF文件。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Open an Excel file
Workbook workbook = new Workbook(dataDir+ "input.xlsx");
// Instantiate PDFSaveOptions to manage security attributes
PdfSaveOptions saveOption = new PdfSaveOptions();
saveOption.SecurityOptions = new Aspose.Cells.Rendering.PdfSecurity.PdfSecurityOptions();
// Set the user password
saveOption.SecurityOptions.UserPassword = "user";
// Set the owner password
saveOption.SecurityOptions.OwnerPassword = "owner";
// Disable extracting content permission
saveOption.SecurityOptions.ExtractContentPermission = false;
// Disable print permission
saveOption.SecurityOptions.PrintPermission = false;
// Save the PDF document with encrypted settings
workbook.Save(dataDir+ "securepdf_test.out.pdf", saveOption);