PDF加密是使用密码以及某些加密算法(包括AES或RC4)来保护文档的过程。您还可以设置不同的特权,以限制用户对不同操作的访问。例如,您只能允许打印,添加注释,填写表格等。
- 使用C ++加密PDF文件
- 使用C ++解密PDF文件
(安装包仅提供部分功能,并设置限制,如需试用完整功能请申请免费授权)
情暖中秋,礼惠国庆!整合所有格式API处理控件Aspose永久授权火热促销中,新购享85折起!联系客服立马1分钟了解全部咨询!
使用C ++加密PDF文件
以下是使用Aspose.PDF for C ++加密PDF文件的步骤。
- 使用Document类加载PDF文档。
- 使用DocumentPrivilege类设置不同的特权,例如允许打印,允许修改内容等。
- 调用Document.Encrypt(String,String,SharedPtr,CryptoAlgorithm,bool)方法来加密PDF。
- 使用Document-> Save(String)方法保存PDF 。
以下代码示例显示了如何使用C ++加密PDF文件。
// Load an existing PDF documentauto 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 way3System::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 documentauto doc = MakeObject(L"..\Data\SecurityAndSignatures\Decrypt.pdf", L"password");// Decrypt PDFdoc->Decrypt();// Save the updated documentdoc->Save(L"..\Data\SecurityAndSignatures\Decrypt_out.pdf");
还想要更多吗可以点击阅读【2020 · Aspose最新资源整合】,查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询。
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!