HTML
JPG
PDF
XML
PDF
PDF
通过 C++ 加密 PDF 文件
将 Excel 电子表格转换为 PDF 文件,并使用 Aspose.Cells C++ 库对其进行密码保护。
如何使用 C++ 加密 PDF 文件
为了加密 PDF 文件,我们将使用
API 是一款功能丰富、功能强大且易于使用的文档加密 API for C++ 平台。您可以直接下载其最新版本,只需打开
包管理器,搜索 Aspose.Cells.Cpp 并安装。您也可以从程序包管理器控制台使用以下命令。
Aspose.Cells
PM> Install-Package Aspose.Cells.Cpp
通过 C++ 加密 PDF 文件的步骤
只需几行代码即可使用 Aspose.Cells API 实现文档保护。
- 使用 Workbook 类加载或创建新的 Excel 文件
- 使用 PdfSecurityOptions 类设置安全选项
- 通过 Save() 方法保存加密的 PDF 文件
系统要求
Aspose.Cells for C++ 支持所有主要平台和操作系统。请确保您满足以下先决条件。
- Microsoft Windows 或与 C++ 运行环境兼容的操作系统,适用于 Windows 32 位、Windows 64 位和 Linux 64 位。
- 在您的项目中添加对 Aspose.Cells for C++ DLL 的引用。
命令
Aspose::Cells::Startup();
//load/creat the Excel file
Workbook wb;
//Set cell value
wb.GetWorksheets().Get(0).GetCells().Get(u"A1").PutValue(u"test");
//Set security options using PdfSecurityOptions class
PdfSecurityOptions securityOptions;
securityOptions.SetOwnerPassword(u"123");
securityOptions.SetPrintPermission(true);
securityOptions.SetAccessibilityExtractContent(true);
//Set saving PDF parameters
PdfSaveOptions pdfSaveOptions;
pdfSaveOptions.SetSecurityOptions(securityOptions);
//Save encrypted PDF files
wb.Save("security.pdf", pdfSaveOptions);
Aspose::Cells::Cleanup();