文檔金喜正規(guī)買(mǎi)球>>Aspose.PDF使用教程>>C++版PDF處理控件Aspose.PDF功能演示:加密或解密PDF文件
C++版PDF處理控件Aspose.PDF功能演示:加密或解密PDF文件
PDF加密是使用密碼以及某些加密算法(包括AES或RC4)來(lái)保護(hù)文檔的過(guò)程。您還可以設(shè)置不同的特權(quán),以限制用戶對(duì)不同操作的訪問(wèn)。例如,您只能允許打印,添加注釋,填寫(xiě)表格等。
在本文中,您將學(xué)習(xí)如何使用C ++加密PDF文件。此外,本文還介紹了如何使用C ++設(shè)置不同的特權(quán)和解密受密碼保護(hù)的PDF文件。
- 使用C ++加密PDF文件
- 使用C ++解密PDF文件
點(diǎn)擊下載最新版Aspose.PDF for C++
(安裝包僅提供部分功能,并設(shè)置限制,如需試用完整功能請(qǐng))
情暖中秋,禮惠國(guó)慶!整合所有格式API處理控件Aspose永久授權(quán)火熱促銷中,新購(gòu)享85折起!立馬1分鐘了解全部咨詢!
使用C ++加密PDF文件
以下是使用Aspose.PDF for C ++加密PDF文件的步驟。
- 使用Document類加載PDF文檔。
- 使用DocumentPrivilege類設(shè)置不同的特權(quán),例如允許打印,允許修改內(nèi)容等。
- 調(diào)用Document.Encrypt(String,String,SharedPtr,CryptoAlgorithm,bool)方法來(lái)加密PDF。
- 使用Document-> Save(String)方法保存PDF 。
以下代碼示例顯示了如何使用C ++加密PDF文件。
// Load an existing PDF document auto doc = MakeObject(L"..\\Data\\SecurityAndSignatures\\input.pdf"); // Way1: Using predefined privilege directly. System::SharedPtrprivilege = Aspose::Pdf::Facades::DocumentPrivilege::get_Print(); doc->Encrypt(L"user", L"owner", privilege, CryptoAlgorithm::AESx128, false); doc->Save(L"..\\Data\\SecurityAndSignatures\\SetPrivelegesWay1_out.pdf"); // Way2: Based on a predefined privilege and change some specifical permissions. System::SharedPtrprivilege2 = Aspose::Pdf::Facades::DocumentPrivilege::get_AllowAll(); privilege->set_AllowPrint(false); privilege->set_AllowModifyContents(false); doc->Encrypt(L"user", L"owner", privilege2, CryptoAlgorithm::AESx128, false); doc->Save(L"..\\Data\\SecurityAndSignatures\\SetPrivelegesWay2_out.pdf"); // Way3: Based on a predefined privilege and change some specifical Adobe Professional permissions combination. System::SharedPtrprivilege3 = Aspose::Pdf::Facades::DocumentPrivilege::get_ForbidAll(); privilege->set_ChangeAllowLevel(1); privilege->set_PrintAllowLevel(2); doc->Encrypt(L"user", L"owner", privilege3, CryptoAlgorithm::AESx128, false); doc->Save(L"..\\Data\\SecurityAndSignatures\\SetPrivelegesWay3_out.pdf"); // Way4: Mixes the way2 and way3 System::SharedPtrprivilege4 = Aspose::Pdf::Facades::DocumentPrivilege::get_ForbidAll(); privilege->set_ChangeAllowLevel(1); privilege->set_AllowPrint(true); doc->Encrypt(L"user", L"owner", privilege4, CryptoAlgorithm::AESx128, false); doc->Save(L"..\\Data\\SecurityAndSignatures\\SetPrivelegesWay4_out.pdf");
使用C ++解密PDF文件
以下是使用Aspose.PDF for C ++解密PDF文件的步驟。
- 使用Document類加載PDF文件,并提供文檔的路徑和密碼。
- 使用Document-> Decrypt()方法解密文件。
- 使用Document-> Save(String)方法保存解密的PDF 。
以下代碼示例顯示了如何使用C ++解密PDF。
// Load an existing PDF document auto doc = MakeObject(L"..\\Data\\SecurityAndSignatures\\Decrypt.pdf", L"password"); // Decrypt PDF doc->Decrypt(); // Save the updated document doc->Save(L"..\\Data\\SecurityAndSignatures\\Decrypt_out.pdf");
還想要更多嗎?您可以點(diǎn)擊閱讀【2020 · Aspose最新資源整合】,查找需要的教程資源。如果您有任何疑問(wèn)或需求,請(qǐng)隨時(shí)加入Aspose技術(shù)交流群(642018183),我們很高興為您提供查詢和咨詢。