We talked before about how to compare two password-protected PDF documents in Java. But what if we want to compare more than just two files? Well, today we’re going to learn how to do just that! We’ll also learn how to accept or reject changes in the documents to get the final version we want.

Compare PDF Documents to find differences using Java API

The recent short series of articles already covered the Java way how to:

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

By the end of this article, you will also have a good understanding of how to:

Before we get started, let’s make sure our development environment is ready to go.

Java Library to Compare Two or More PDF Files

I believe you are familiar with the document comparison Java API by now. I will be using the same GroupDocs.Comparison for Java to move ahead. You can download or quickly check the development environment of your maven-based applications using the following configurations:

    <name>GroupDocs Artifacts Repository</name>

Now, let’s move on to the real stuff!

Compare More than Two PDF Files using Java

Comparing multiple files is pretty similar to comparing just two. All we have to do is add more files to the Comparer and then hit compare like we normally would. Here are the steps to compare multiple PDF documents and highlight the identified changes:

  • Load the first PDF file using the Comparer class.
  • Utilize the add method to add any additional documents to be compared to the Comparer.
  • Compare all subsequent PDF files using the compare method and obtain the changes and summary of differences.

The following example shows how to compare multiple PDF files in Java and get the changes in the resultant document.

Compare and Accept or Reject Identified Changes of PDF Files using Java

Quite similar to the functionality of the “track changes” feature in Microsoft Word, it is also possible to accept or reject each detected change in PDF documents through programming. The steps below demonstrate how to compare and then accept or reject the changes that have been identified within the PDF documents.

  • Load the source and target PDF files using the Comparer class.
  • Compare the loaded documents using compare method.
  • Get the identified changes using the getChanges method.
  • Now traverse the changes and set the appropriate ComparisonAction.
    • Select Accept to adopt the change
    • Select Reject to deny the change.
  • Call the applyChanges method to get the resultant document with the accepted changes.

The following code snippet compares two PDF documents and then accepts an identified change and then rejects another one using Java.

Get a Free API License

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

Build Your Own PDF Comparison Application

Here are some important links that will help you in building your own document comparison application.

Features | Documentation | API Reference | Running Examples – GitHub | Free Support Forum | Release Notes

See Also