GroupDocs.Merger for Python via .NET lets you remove an open password from a protected document. After the operation the saved document is unencrypted and can be opened without any password.
Steps to remove a document password
Create a LoadOptions instance and supply the current password so the document can be opened.
Instantiate the Merger class with the protected document path and the LoadOptions object.
Call merger.remove_password() to strip the password.
Call merger.save() with the output file path to write the decrypted document.
fromgroupdocs.mergerimportMergerfromgroupdocs.merger.domain.optionsimportLoadOptionsdefremove_document_password():# Supply the current password so the protected document can be openedload_options=LoadOptions(password="p@ss")# Load the password-protected documentwithMerger("./protected.pdf",load_options)asmerger:# Remove the open password from the documentmerger.remove_password()# Save the decrypted (unprotected) documentmerger.save("./output.pdf")if__name__=="__main__":remove_document_password()
protected.pdf is a sample file used in this example. Click here to download it.
Load Options: LoadOptions(password="p@ss") provides the current document password so that Merger can decrypt and open the file. Omitting the password when the document is protected raises IncorrectPasswordException.
Load Document: The Merger context manager opens the protected file using the supplied credentials.
Remove Password: merger.remove_password() clears the open password from the in-memory document representation.
Save Result: merger.save() writes the now-unprotected document to disk.