As PDF is among the most widely used digital formats, it’s often required to compare two versions of the same document. This article outlines how to compare two PDF documents for differences using Java. Very soon, we will also discuss how to compare password-protected PDF files, compare multiple PDF documents and accept or reject changes by providing examples of comparing the PDF files using Java.

Compare PDF Documents to find differences using Java API

If you are interested in Comparing PDF Files Online, visit the Online PDF Comparison Tool that is powered by GroupDocs.

Java API to Compare PDF Files

In this article, I will utilize the GroupDocs.Comparison for Java API to compare two 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 PDF Documents using Java

To detect any differences between the two PDF versions, it is possible to compare them and identify any added, deleted, or altered content. By doing so, a new document is generated, which displays all the detected changes.

The following steps describe the process for comparing any two PDF files and highlighting any variations.

  • Load the first PDF document using Comparer class.
  • Add the second file to Comparer using add method.
  • Compare both the PDF files and get the changes summary by calling compare method.

The following Java code snippet shows how to compare PDF documents and highlight the changes in the resultant document.

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

Comparison Result - Comparing PDF Files using Java

Get a Free API License

You can get a free temporary license to use the API without the evaluation limitations.


In summary, we have acquired knowledge on a straightforward approach to comparing two PDF files using Java. The resulting output is a summary of any added or removed content. In next articles, we will explore additional methods for comparing secured PDF documents, comparing multiple PDF files and accepting or rejecting detected changes.

Why not try creating your own Java-based document comparison application? Additional insights into APIs can be gained by referring to the documentation and API reference.

To easily access examples, GitHub repository is a great resource. If you have any questions, feel free to contact us via the forum.

Related Article

See Also