We just learned the basic comparison of DOC/DOCX files. What if, the file(s) are locked or password protected? In this article, we will look at how to compare two or more Word documents in Java if they are password protected.

Compare Protected Word Documents to find differences in Java

MS Word is among the top rich-text editors that are used to draft official documents, invoices, reports, and personal documents. DOC and DOCX are the file formats of word-processing documents that are in vast use.

As a Java programmer, you often need to compare two different versions of the same document. So let’s see in this article, how to compare two password-protected Word documents in Java.

Java Library to Compare Protected Word Documents

GroupDocs.Comparison for Java is a robust document and image comparison API for developers. Using this library, you can easily perform comparisons between multiple files. Today, we will use it to compare two or more password-protected documents in Java.

You may download the JAR file from the downloads section, or just get the repository and dependency configurations for the pom.xml of your maven-based Java applications.

	<name>GroupDocs Java API</name>

Steps to Compare Protected Word Documents in Java

To compare two protected Word documents in Java using GroupDocs.Comparison, we will perform the following steps:

  • Load the first Word document by providing the file’s password.
  • Load the second document. (Provide its password if it is also protected)
  • Compare both the loaded document.

It’s all done. Check the results.

Now, let’s implement these steps in Java to compare two protected Word documents.

Compare Protected Word Documents in Java

The following are the steps for the comparison of any two password-protected Word documents (DOC, DOCX) and highlighting their differences in Java.

  • Prepare the loading option using the LoadOptions class.
  • Load the first Word document using the Comparer class and loading options.
  • Add the second file to the Comparer using add() method.
  • Finally, call the compare() method to get the comparison summary of the found changes.

The following Java code shows how to compare protected Word documents and get the changes in the resultant document.

Here is the output after comparing two protected Word files using the above code:

Compare Word Documents to find differences

Get a Free API License

You can get a free temporary license to use the API without the evaluation limitations to compare multiple protected word documents.


To conclude, we learned the comparison of two password-protected Word documents in Java. As a result, you got the summary of added and deleted content. In a separate article, we will discuss way to compare more than two Word documents and accept or reject the identified changes.

You can also try building your online Java application for document comparison. Learn more about the APIs using its documentation and API References.

The easy way to experience the examples is from GitHub. Contact us for any query via the forum.

See Also