How to Protect PPTX Presentation Using C++

This topic shows, how to protect PPTX Presentation using C++ by setting a password for encryption. There are different ways one can secure the PowerPoint presentation like by applying a textual or image watermark or making it read only. In this tutorial, we’ll be programmatically setting password for protecting presentation using C++.

Steps to Lock PowerPoint Presentation in C++

  1. Use Aspose.Slides for C++ NuGet package
  2. Add reference to Aspose::Slides and Export namespaces
  3. Load the presentation file for protection using Presentation class instance
  4. Use Encrypt method exposed by ProtectionManager class to secure presentation with a password
  5. Save the password protected presentation using Save method and saving as PPTX

The Aspose.Slides for C++ API can help you to secure PowerPoint presentation using C++ without any reliance on Microsoft Interop or even Microsoft PowerPoint being installed on your machine.

Code to Lock PowerPoint Presentation in C++

#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);
}
};

Earlier, in another how-to topic, we have looked How to Insert Draft Watermark in PowerPoint Presentation in C#. But in the above example we have seen how to secure PPTX presentation in C++. The API also have provision to unlock the protection on presentation by removing password in C++ as well. There are few lines of code in C++ allowing you to secure your presentation.

 English