通过 Node.js 和 C++ 使用 Node.js 安全保护 PDF 文档

Contents
[ ]

Aspose.Cells 提供 PdfSecurityOptions 支持安全性功能。保存为 PDF 时,可以设置所有者密码和用户密码。加密的 PDF 文件需要这些密码才能打开查看。

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

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

const path = require("path");
const AsposeCells = require("aspose.cells.node");

const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "input.xlsx");
const workbook = new AsposeCells.Workbook(filePath);

const saveOption = new AsposeCells.PdfSaveOptions();
saveOption.setSecurityOptions(new AsposeCells.PdfSecurityOptions());

saveOption.getSecurityOptions().setUserPassword("user");
saveOption.getSecurityOptions().setOwnerPassword("owner");
saveOption.getSecurityOptions().setExtractContentPermission(false);
saveOption.getSecurityOptions().setPrintPermission(false);

workbook.save(path.join(dataDir, "securepdf_test.out.pdf"), saveOption);