As Java programmer, we often need to compare two versions of the same/similar document. We have already seen the basic comparison of two PDF files, but what if these files are encrypted or have password protection? This article explores how to compare two password-protected PDF documents in Java.
Java API to Compare Protected PDF Files
In this article, I will utilize the GroupDocs.Comparison for Java API to compare PDF documents, as this API enables comparison among multiple PDF documents. Additionally, it allows the comparison of various other files of the same document format within Java applications.
You can download the JAR file from the downloads section or use the latest repository and dependency Maven configurations within your Java applications.
<name>GroupDocs Artifacts Repository</name>
Compare Password Protected PDF Documents using Java
It is easily possible to compare password-protected files by providing their passwords while loading the documents. The following steps demonstrate how to compare the content of password-protected PDF documents using Java:
- Prepare loading options for both the source and target documents, providing the necessary passwords.
- Load the source document using the Comparer class.
- Add the target document to the Comparer, using the prepared loading options.
- Obtain a summary of the differences by calling the compare method.
The Java example below compares two password-protected PDF files and highlights the identified differences in a separate document.
Here is the output after comparing two protected PDF files using the above code:
Get a Free API License
You can get a free temporary license to use the API without the evaluation limitations.
So to wrap up, we learned how to compare two PDF files that have passwords in Java. This lets you see what’s been added and what’s deleted.
In another article, we’ll talk about how to compare more than two PDFs in Java and decide if you want to keep the changes.