C++版PDF处理控件Aspose.PDF功能演示:加密或解密PDF文件

Aspose.PDF 是一款高级PDF处理API,可以在跨平台应用程序中轻松生成,修改,转换,呈现,保护和打印文档。无需使用Adobe Acrobat。此外,API提供压缩选项,表创建和处理,图形和图像功能,广泛的超链接功能,图章和水印任务,扩展的安全控件和自定义字体处理。

Aspose API支持流行文件格式处理,并允许将各类文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。

PDF加密是使用密码以及某些加密算法(包括AES或RC4)来保护文档的过程。您还可以设置不同的特权,以限制用户对不同操作的访问。例如,您只能允许打印,添加注释,填写表格等。

在本文中,您将学习如何使用C ++加密PDF文件。此外,本文还介绍了如何使用C ++设置不同的特权和解密受密码保护的PDF文件。

  • 使用C ++加密PDF文件
  • 使用C ++解密PDF文件

点击下载最新版Aspose.PDF for C++(qun:761297826)icon-default.png?t=N6B9https://www.evget.com/product/4118/download


使用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 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");
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值