Get changes coordinates

On this page

GroupDocs.Comparison allows you to detect changes between the source and target documents and get coordinates of the changes in the document preview images. These coordinates can be useful to highlight changes in the document preview images.

To get the coordinates 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. Instantiate the CompareOptions object. Call the setCalculateCoordinates to get coordinates.
  4. Call the compare() method. Specify the CompareOptions object from the previous step.
  5. Call the getChanges() method.

The following code snippet shows how to compare multiple documents with specific options:

const comparer = new groupdocs.comparison.Comparer(sourceFile);
comparer.add(targetFile);

const compareOptions = new groupdocs.comparison.CompareOptions();
compareOptions.setCalculateCoordinates(true);
const resultPath = comparer.compare(resultFile, compareOptions);

let changes = comparer.getChanges();
for (ChangeInfo change : changes) {
    System.out.printf("Change Type: %d, X: %f, Y: %f, Text: %s%n",
        change.getType(), change.getBox().getX(), change.getBox().getY(), change.getText());
}

The result is as follows:

On this page