Get list of changes

GroupDocs.Comparison allows you to get list of changes between source and target documents.

To get list of changes, follow these steps:

  1. Instantiate the Comparer object. Specify the source document path or stream.
  2. Call the add() method. Specify the target document path or stream.
  3. Call the compare() method.
  4. Call the getChanges method.

The following code snippets show how to get list of all changes:

Get list of changes from local disk

import com.groupdocs.comparison.Comparer;
import com.groupdocs.comparison.result.ChangeInfo;
// ...

try (Comparer comparer = new Comparer("source.docx")) {
    comparer.add("target.docx");
    comparer.compare();
    ChangeInfo[] changes = comparer.getChanges();
    for (ChangeInfo change : changes) {
        System.out.println("Change Type: " + change.getType() +
                           ", Page: " + change.getPageInfo().getPageNumber() +
                           ", Change ID: " + change.getId() +
                           ", Text: " + change.getText());
    }
}

The result is as follows:

Get list of changes from stream

import com.groupdocs.comparison.Comparer;
import com.groupdocs.comparison.result.ChangeInfo;
import java.io.FileInputStream;
import java.io.InputStream;
// ...

try (final FileInputStream sourceInputStream = new FileInputStream("source.docx");
    final Comparer comparer = new Comparer(sourceInputStream);
    final FileInputStream targetInputStream = new FileInputStream("target.docx")) {
    comparer.add(targetInputStream);
    comparer.compare();
    ChangeInfo[] changes = comparer.getChanges();
    for (ChangeInfo change : changes) {
        System.out.println("Change Type: " + change.getType() +
                            ", Page: " + change.getPageInfo().getPageNumber() +
                            ", Change ID: " + change.getId() +
                            ", Text: " + change.getText());
    }
}