How to Convert Protected Word Document to Unprotected in Python

This quick tutorial guides on how to convert protected Word document to unprotected in Python. It shares all the requirements to accomplish this task along with the detailed steps and a runnable sample code that can be executed in any of the environments supporting Java. During this process to unprotect MS Word document in Python, you will also learn different options to remove the protection and save the resultant file in any of the desired formats like DOCX, DOC, or in any other format supported by MS Word.

Steps to Unprotect Word Document in Python

  1. Establish the environment to use Aspose.Words for Python via .NET for removing the protection from the Word file
  2. Open the protected Word file using the Document class object
  3. Call the unprotect() method in the Document class to remove protection
  4. Save the output Word file after removing the protection

The above steps explain the process to unprotect Word document without password in Python where the protected Word file is loaded into the Document class object. Once the source file is opened, the unprotect() method is called to remove both types of protections from the loaded file that is protected with or without a password. The resultant Word file whose protection is removed can be saved with the same name or as a new file as per the requirements.

Code to Unprotect Word File in Python

The above code demonstrates the process to convert protected Word document to unprotected in Python where the Document class object is used with the single argument constructor. If you want to provide a password to open the Word file, you may use the other constructor that takes the LoadOptions object with the required password to open the loaded Word file. Similarly, if your Word file is write-protected, use the method Document.write_protection.set_password() by providing the password as an argument.

In this article, we have gone through the process to remove the protection from a Word file. If you want to learn the process to apply a password to a Word file, refer to the article on how to password protect a Word document in Python.

 English