本主题展示如何通过设置加密密码来使用 C++ 保护 PPTX 演示文稿。有多种方法可以保护 PowerPoint presentation,例如应用文本或图像水印或使其只读。在本教程中,我们将以编程方式设置密码以使用 C++ 保护演示文稿。
在 C++ 中锁定 PowerPoint 演示文稿的步骤
- 使用 Aspose.Slides for C++ NuGet 包
- 添加对 Aspose::Slides 和导出命名空间的引用
- 使用 Presentation 类实例加载演示文件以进行保护
- 使用 ProtectionManager 类公开的 Encrypt 方法通过密码保护演示文稿
- 使用 Save 方法保存受密码保护的演示文稿并另存为 PPTX
Aspose.Slides for C++ API 可以帮助您使用 C++ 保护 PowerPoint 演示文稿,而无需任何依赖 Microsoft Interop 甚至您的计算机上安装的 Microsoft PowerPoint。
用 C++ 锁定 PowerPoint 演示文稿的代码
#pragma once | |
#include <DOM/Presentation.h> | |
#include <Util/License.h> | |
#include <Export/SaveFormat.h> | |
#include <DOM/ProtectionManager.h> | |
using namespace Aspose::Slides; | |
using namespace Aspose::Slides::Export; | |
using namespace System; | |
class ProtectPresentationEx { | |
public: | |
static void SaveWithPassword() | |
{ | |
//Set Aspose license before securing PowerPoint presentation | |
//using Aspose.Slides for C++ | |
const String LicPath = u"Aspose.Total.NET.lic"; | |
SharedPtr<License> lic = MakeObject<License>(); | |
lic->SetLicense(LicPath); | |
//create an object of Presentation class from Aspose.Slides namespace | |
//and provide the PowerPoint presentation to secure in the constructor | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(u"Input.pptx"); | |
//specify the password with which you want to secure the presentation | |
//this can be taken as input password from the user/admin etc. | |
const String PasswordForPresentationSecurity = u"8ma2bzdqgo"; | |
pres->get_ProtectionManager()->Encrypt(PasswordForPresentationSecurity); | |
//Finally, save the output presentation secured with password | |
//provide PPTX as save format | |
pres->Save(u"PresentationSecuredWithPassword.pptx", SaveFormat::Pptx); | |
} | |
}; |
早些时候,在另一个操作方法主题中,我们查看了 如何在 C# 的 PowerPoint 演示文稿中插入草稿水印。但是在上面的例子中,我们已经看到了如何在 C++ 中保护 PPTX 表示。 API 还可以通过删除 C++ 中的密码来解锁演示文稿保护。 C++ 中有几行代码可让您保护您的演示文稿。