Using our programming API, you can compare two files and find the difference between them. In other words, our Java library is a powerful file difference checker. After using Document Comparison API, you can get the result and save it in DOCX, PDF, DOC and some other formats.
Comparing documents is a very complex function. But we implemented our solution so that you get the most accurate result. Instead of looking for document differences manually, use our Java API to compare docs.
Document comparing is performed by comparing words at the level of characters or whole words. In this case, if only a character was changed, the word will be highlighted as the whole changed.
The most popular are Word Compare and PDF Compare. Therefore, we will show the Java Comparison API using the example of comparing Word files and comparing PDF documents.
Comparing PDF files programmatically is a typical task of modern digital workflow. This may be required when you are not sure that your document has not been modified. Or when you know your original PDF has been updated and you want to know how.
To compare two PDFs, just verify them with our Java library. It allows you to diff PDF and find even small changes that would be invisible to the human eye.
To compare two Word documents in Java you need to do the same: diff them using our powerful Java library through the example below.
Unlike PDFs, Word documents are easier to change, which is why it can be so important to compare Word documents if you need to make sure that some parts of it or an entire file are unchanged.
To test how our Java solution works and to diff two files, import files you want to compare and choose an export file format. After files are compared, the document containing the difference of this comparison will be automatically downloaded.
Note that documents to compare should not have any revisions before calling the compare method, so we took care of that in our example:
import com.aspose.words.*;
Document docA = new Document("Input1.docx");
Document docB = new Document("Input2.docx");
// There should be no revisions before comparison.
docA.acceptAllRevisions();
docB.acceptAllRevisions();
docA.compare(docB, "Author Name", new Date());
docA.save("Output.docx");
We host our Java packages in Maven repositories. 'Aspose.Words for Java' is a common JAR file containing byte-code. Please follow the step-by-step instructions on how to install it to your Java developer environment.
Java SE 7 and more recent Java versions are supported. We also provide a separate package for Java SE 6 in case you are obliged to use this outdated JRE.
Our Java package is cross-platform and runs on all operating systems with JVM implementation, including Microsoft Windows, Linux, macOS, Android and iOS.
For information on optional package dependencies, such as JogAmp JOGL, Harfbuzz font engine, Java Advanced Imaging JAI, please refer to Product Documentation.