This short tutorial provides details on how to unprotect Word file in Java. It has all the required information to establish the environment along with the detailed steps to create this application and a runnable sample code. Once you convert protected Word document to unprotected in Java, you can save it as a separate DOCX, DOC, or in any of the supported formats.
Steps to Unprotect MS Word Document in Java
- Set the IDE configuration to use Aspose.Words for Java from the repository to remove protection
- Open the source Word file that is protected using the Document class object
- Call the unprotect() method to unprotect the loaded file
- Save the resultant unprotected file on the disk or to a stream
These steps share a systematic approach to develop an application to unprotect Word document in Java and then save the output file as a new file on the disk or save it with the same name if required. All the important classes and methods are introduced here that are necessary to achieve the requirement. It also contains the link to the library that is used in this article and needs to be downloaded for testing the sample code.
Code to Unprotect DOCX in Java
This code demonstrates the simple process to unprotect Word document without password in Java. It uses the Document class object to load the protected Word document and then uses unprotect() method without any argument to remove the protection. If the Word file is protected with a password, you may provide the password in the unprotect() method however it can remove the password-protected protection also without providing any password.
This article has taught us to remove Word file protection. If you want to learn the process to protect a Word file with a password, refer to the article on how to add password to Word document using Java.