通過C++加密 PDF 檔

使用C++設置具有 AES-128 加密的 PDF 格式的文件許可權

如何使用 C++ 庫保護PDF檔

為了保護PDF檔,我們將使用[Aspose.PDF for C++](https://products.aspose.com/pdf/cpp)API,這是一個功能豐富,功能強大且易於使用的文檔操作API,適用於 cpp 平臺。打開 [NuGet](https://www.nuget.org/packages/aspose.pdf) 包管理器,搜索“.PDF”並安裝。您也可以從程式包管理器主控台使用以下命令。

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

通過C++保護 PDF


您需要為C++.PDF [Aspose https://releases.aspose.com/pdf/cpp) 才能在您的環境中嘗試代碼。

  1. 載入包含文件實例的 PDF。
  2. 建立文件特權的物件 > 設定選項。
  3. 呼叫文件加密方法,使用 AES-128 保護 PDF。
  4. 以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.