Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created April 5, 2024 05:17
Unlock Password Protected Documents via C++ Applications

Unlock Microsoft Word Documents, Excel Spreadsheets, Powerpoint Presentations and PDF Documents by removing password or write protection via C++ Application

Aspose::Cells::Startup();
Workbook workbook(u"protected.xlsx");
Worksheet worksheet = workbook.GetWorksheets().Get(0);
worksheet.Unprotect();
workbook.Unprotect("password");
workbook.Save("unprotected.xlsx", SaveFormat::Auto);
Aspose::Cells::Cleanup();
String _dataDir("C:\\Samples\\");
auto pdfDocument = MakeObject<Document>(_dataDir + u"Decrypt.pdf", u"password");
pdfDocument->Decrypt();
pdfDocument->Save(_dataDir + u"unlocked.pdf");
auto loadOptions = System::MakeObject<LoadOptions>();
loadOptions->set_Password(u"123123");
auto presentation = System::MakeObject<Presentation>(u"pres.pptx", loadOptions);
presentation->get_ProtectionManager()->RemoveEncryption();
presentation->Save(u"encryption-removed.pptx", SaveFormat::Pptx);
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputFileName);
doc->Unprotect();
doc->Save(u"unprotected.doc");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment