Protect PDF via C++

Set document privileges for PDF with AES-128 encryption. Use Aspose.PDF for C++ to modify PDF documents programmatically

How to Protect PDF File Using Using C++ Tool

In order to protect PDF file, we’ll use Aspose.PDF for C++ API which is a feature-rich, powerful and easy to use document manipulation API for cpp platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

Protect PDF via C++


You need Aspose.PDF for C++ to try the code in your environment.

  1. Load the PDF with an instance of Document.
  2. Create an object of DocumentPrivilege & set options.
  3. Call Document.Encrypt method to protect PDF with AES-128.
  4. Save result in PDF format

Protect PDF - C++

This sample code shows how to protect PDF File


// Load an existing PDF document
auto doc = MakeObject<Document>(L"..\\sourcePath\\sourceFile.pdf");

// Use predefined privilege directly.
System::SharedPtr<Aspose::Pdf::Facades::DocumentPrivilege> privilege = Aspose::Pdf::Facades::DocumentPrivilege::get_Print();
doc->Encrypt(L"user", L"owner", privilege, CryptoAlgorithm::AESx128, false);
doc->Save(L"..\\outputPath\\protectedFile.pdf");
//few other ways as well like
// Use predefined privilege and change some specifical permissions.
// Use predefined privilege and change some specifical Adobe Professional permissions combination.