Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aspose-com-gists/0e5a45839a6a8a82a098aeead8c4e2f6 to your computer and use it in GitHub Desktop.

Select an option

Save aspose-com-gists/0e5a45839a6a8a82a098aeead8c4e2f6 to your computer and use it in GitHub Desktop.
Remove Password Protection from Documents using Java
Presentation pres = new Presentation("write-protected-presentation.pptx");
try {
pres.getProtectionManager().removeWriteProtection();
pres.save("write-protection-removed.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
LoadOptions lOp = new LoadOptions();
lOp.setPassword("321321");
Presentation pres = new Presentation("presntation.pptx", lOp);
try {
pres.getProtectionManager().removeEncryption();
pres.save("encryption-removed.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
Workbook wkb = new Workbook("workbook.xlsx");
WorksheetCollection worksheets = wkb.getWorksheets();
Worksheet wks = worksheets.get(0);
wks.unprotect("12345");
wkb.save("workbook_updated.xlsx");
Document pdfDoc = new Document(_dataDir + "Decrypt.pdf", "password");
pdfDoc.decrypt();
pdfDoc.save(_dataDir + "password-removed.pdf");
Document doc = new Document("password-protected-file.docx");
doc.unprotect();
doc.save("password-removed.docx");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment