Customize changes styles
Leave feedback
On this page
GroupDocs.Comparison provides the compare options collection to set up the appropriate comparison speed and quality.
To compare two documents with custom change style settings, 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. Specify the appropriate parameters.
- Call the compare() method. Specify the CompareOptions object.
The following code snippets show how to compare documents with specific options:
try (Comparer comparer = new Comparer(sourceFile)) {
comparer.add(targetFile);
CompareOptions compareOptions = new CompareOptions();
final StyleSettings insertedStyleSettings = new StyleSettings();
insertedStyleSettings.setHighlightColor(Color.RED);
insertedStyleSettings.setFontColor(Color.GREEN);
insertedStyleSettings.setUnderline(true);
insertedStyleSettings.setBold(true);
insertedStyleSettings.setStrikethrough(true);
insertedStyleSettings.setItalic(true);
compareOptions.setInsertedItemStyle(insertedStyleSettings);
final StyleSettings deletedStyleSettings = new StyleSettings();
deletedStyleSettings.setHighlightColor(Color.PINK);
deletedStyleSettings.setFontColor(Color.CYAN);
deletedStyleSettings.setUnderline(true);
deletedStyleSettings.setBold(true);
deletedStyleSettings.setStrikethrough(true);
deletedStyleSettings.setItalic(true);
compareOptions.setDeletedItemStyle(deletedStyleSettings);
final StyleSettings changedStyleSettings = new StyleSettings();
changedStyleSettings.setHighlightColor(Color.LIGHT_GRAY);
changedStyleSettings.setFontColor(Color.GRAY);
changedStyleSettings.setUnderline(true);
changedStyleSettings.setBold(true);
changedStyleSettings.setStrikethrough(true);
changedStyleSettings.setItalic(true);
compareOptions.setChangedItemStyle(changedStyleSettings);
final Path resultPath = comparer.compare(resultFile, compareOptions);
}
The result is as follows:
try (Comparer comparer = new Comparer(sourceInputStream)) {
comparer.add(targetInputStream);
CompareOptions compareOptions = new CompareOptions();
final StyleSettings insertedStyleSettings = new StyleSettings();
insertedStyleSettings.setHighlightColor(Color.RED);
insertedStyleSettings.setFontColor(Color.GREEN);
insertedStyleSettings.setUnderline(true);
insertedStyleSettings.setBold(true);
insertedStyleSettings.setStrikethrough(true);
insertedStyleSettings.setItalic(true);
compareOptions.setInsertedItemStyle(insertedStyleSettings);
final StyleSettings deletedStyleSettings = new StyleSettings();
deletedStyleSettings.setHighlightColor(Color.PINK);
deletedStyleSettings.setFontColor(Color.CYAN);
deletedStyleSettings.setUnderline(true);
deletedStyleSettings.setBold(true);
deletedStyleSettings.setStrikethrough(true);
deletedStyleSettings.setItalic(true);
compareOptions.setDeletedItemStyle(deletedStyleSettings);
final StyleSettings changedStyleSettings = new StyleSettings();
changedStyleSettings.setHighlightColor(Color.LIGHT_GRAY);
changedStyleSettings.setFontColor(Color.GRAY);
changedStyleSettings.setUnderline(true);
changedStyleSettings.setBold(true);
changedStyleSettings.setStrikethrough(true);
changedStyleSettings.setItalic(true);
compareOptions.setChangedItemStyle(changedStyleSettings);
final Path resultPath = comparer.compare(resultInputStream, compareOptions);
}
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.