Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Compare Word Documents and Highlight Differences using Java
Compare Word Documents and Highlight Differences using Java:
1. Compare Two Word Documents using Java
2. Word Documents Comparison with Compare Options using Java
3. Compare Bookmarks in Word Documents
// initialize comparer
Comparer comparer = new Comparer("C:\\Files\\source.docx");
// add target file
comparer.add("C:\\Files\\target.docx");
// define compare options
CompareOptions compareOptions = new CompareOptions();
compareOptions.setCompareBookmarks(true);
// compare and save compare results
comparer.compare("C:\\Files\\result.docx", compareOptions);
// initialize comparer
Comparer comparer = new Comparer("C:\\Files\\source.docx");
// add target file
comparer.add("C:\\Files\\target.docx");
// compare and save compare results
comparer.compare("C:\\Files\\result.docx");
// initialize comparer
Comparer comparer = new Comparer("C:\\Files\\source.docx");
// add target file
comparer.add("C:\\Files\\target.docx");
// compare
final Path resultPath = comparer.compare();
// get changes
ChangeInfo[] changes = comparer.getChanges();
System.out.println("Count of changes: " + changes.length);
for (ChangeInfo change : changes) {
System.out.printf("Change Type: %d, Text: %s%n", change.getType(), change.getText());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment