通过 C++ 加密 PDF 文件

使用 C++ 为采用 AES-128 加密的 PDF 格式设置文档权限

如何使用 C++ 库保护 PDF 文件

为了保护 PDF 文件,我们将使用 Aspose.PDF for C++ API,这是一款功能丰富、功能强大且易于使用的适用于 cpp 平台的文档处理 API。打开 NuGet 软件包管理器,搜索 aspose.pdf 然后安装。您也可以从软件包管理器控制台使用以下命令。

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

通过 C++ 保护 PDF


你需要 Aspose.PDF for C++ 才能在你的环境中试用这些代码。

1.使用 “文档” 实例加载 PDF。 1.创建 documentPrivilege 对象并设置选项。 1.调用 Document.Encrypt 方法使用 AES-128 保护 PDF。 1.将结果保存为 PDF 格式

保护 PDF-C++。

<% protect.code-block.subtitle %>


// Load an existing PDF document
auto doc = MakeObject<Document>(L"..\sourcePath\sourceFile.pdf");

// Use predefined privilege directly.
System::SharedPtr<Aspose::Pdf::Facades::DocumentPrivilege> privilege = Aspose::Pdf::Facades::DocumentPrivilege::get_Print();
doc->Encrypt(L"user", L"owner", privilege, CryptoAlgorithm::AESx128, false);
doc->Save(L"..\outputPath\protectedFile.pdf");
//few other ways as well like
// Use predefined privilege and change some specifical permissions.
// Use predefined privilege and change some specifical Adobe Professional permissions combination.