Customize changes styles

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:

  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. Specify the appropriate parameters.
  4. Call the compare() method. Specify the CompareOptions object.

The following code snippets show how to compare documents with specific options:

Compare documents from a local disk with custom change styles

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

const compareOptions = new groupdocs.comparison.CompareOptions();

const insertedStyleSettings = new groupdocs.comparison.StyleSettings();
insertedStyleSettings.setHighlightColor(Color.RED);
insertedStyleSettings.setFontColor(Color.GREEN);
insertedStyleSettings.setUnderline(true);
insertedStyleSettings.setBold(true);
insertedStyleSettings.setStrikethrough(true);
insertedStyleSettings.setItalic(true);
compareOptions.setInsertedItemStyle(insertedStyleSettings);

const deletedStyleSettings = new groupdocs.comparison.StyleSettings();
deletedStyleSettings.setHighlightColor(Color.PINK);
deletedStyleSettings.setFontColor(Color.CYAN);
deletedStyleSettings.setUnderline(true);
deletedStyleSettings.setBold(true);
deletedStyleSettings.setStrikethrough(true);
deletedStyleSettings.setItalic(true);
compareOptions.setDeletedItemStyle(deletedStyleSettings);

const changedStyleSettings = new groupdocs.comparison.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);

const resultPath = comparer.compare(resultFile, compareOptions);

The result is as follows:

Compare documents from a stream with custom change styles

const comparer = new groupdocs.comparison.Comparer(sourceInputStream);
comparer.add(targetInputStream);

const compareOptions = new groupdocs.comparison.CompareOptions();

const insertedStyleSettings = new groupdocs.comparison.StyleSettings();
insertedStyleSettings.setHighlightColor(Color.RED);
insertedStyleSettings.setFontColor(Color.GREEN);
insertedStyleSettings.setUnderline(true);
insertedStyleSettings.setBold(true);
insertedStyleSettings.setStrikethrough(true);
insertedStyleSettings.setItalic(true);
compareOptions.setInsertedItemStyle(insertedStyleSettings);

const deletedStyleSettings = new groupdocs.comparison.StyleSettings();
deletedStyleSettings.setHighlightColor(Color.PINK);
deletedStyleSettings.setFontColor(Color.CYAN);
deletedStyleSettings.setUnderline(true);
deletedStyleSettings.setBold(true);
deletedStyleSettings.setStrikethrough(true);
deletedStyleSettings.setItalic(true);
compareOptions.setDeletedItemStyle(deletedStyleSettings);

const changedStyleSettings = new groupdocs.comparison.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);

const resultPath = comparer.compare(resultInputStream, compareOptions);