通过 C++ 保护 PDF

使用 AES-128 加密为 PDF 设置文档权限。使用 Aspose.PDF for C++ 以编程方式修改 PDF 文档

如何使用使用 C++ 工具保护 PDF 文件

為了保護 PDF 文件,我們將使用 Aspose.PDF for C++ API,它是一款功能豐富、強大且易於使用的文件操作 API,適用於 cpp 平台。開啟 NuGet 套件管理器,搜尋 Aspose.PDF 並安裝。您也可以在套件管理器控制台中使用下列命令。

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

通過C++保護 PDF


您需要為 Aspose.PDF for C++ 才能在您的環境中嘗試代碼。

  1. 使用 Document 實例載入 PDF。
  2. 建立 DocumentPrivilege 物件並設定選項。
  3. 呼叫 Document.Encrypt 方法使用 AES-128 加密 PDF。
  4. 以 PDF 格式儲存結果

保護 PDF - C++

此示例代码显示了如何保护 PDF 文件


// 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.