Get changes coordinates
Leave feedback
On this page
GroupDocs.Comparison allows you to detect changes between source and target documents and get changes coordinates at document preview images. These coordinates can be useful to highlight changes at the document preview images.
To get the changes coordinates, follow these steps:
- Instantiate the Comparer object. Specify the source document path or stream.
- Call the add() method. Specify the target document path or stream.
- Instantiate the CompareOptions object. Call the setCalculateCoordinates to get coordinates.
- Call the compare() method. Specify the CompareOptions object from the previous step.
- Call the getChanges() method.
The following code snippet shows how to compare multiple documents with specific options:
import com.groupdocs.comparison.Comparer;
import com.groupdocs.comparison.options.CompareOptions;
import com.groupdocs.comparison.result.ChangeInfo;
import java.nio.file.Path;
// ...
try (Comparer comparer = new Comparer("source.docx")) {
comparer.add("target.docx");
CompareOptions compareOptions = new CompareOptions();
compareOptions.setCalculateCoordinates(true);
final Path resultPath = comparer.compare("result.docx", compareOptions);
ChangeInfo[] 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:
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.