Word document comparison options


GroupDocs.Comparison provides the WordCompareOptions class for configuring comparison of Word documents (.doc, .docx, .rtf, and other word-processing formats). It extends CompareOptions and adds Word-specific properties — most notably the DisplayMode property, which controls how detected changes are written into the result document.

Display modes

The setDisplayMode() method accepts one of two values from the WordCompareOptions.ComparisonDisplayMode enumeration:

  • REVISIONS (default) — changes are emitted as native Word revision (track-changes) markup. The result opens in Microsoft Word with the Review → Accept / Reject controls ready.
  • HIGHLIGHT — inserted, deleted, and modified text is rendered with inline colour highlights directly in the document body. No track-changes metadata is added.
Note
A plain CompareOptions object keeps producing highlighted output, as before. Track-changes output is the default only when you pass a WordCompareOptions object.

Revisions mode

import com.groupdocs.comparison.Comparer;
import com.groupdocs.comparison.options.WordCompareOptions;
// ...

try (Comparer comparer = new Comparer("source.docx")) {
    comparer.add("target.docx");

    WordCompareOptions options = new WordCompareOptions();
    options.setDisplayMode(WordCompareOptions.ComparisonDisplayMode.REVISIONS);

    comparer.compare("result.docx", options);
}

The result:

Revisions mode

In this mode the changes live in the result document as Word revisions, so Comparer.getChanges() is not available after the comparison. Use HIGHLIGHT mode when you need the list of changes from the API.

Highlight mode

import com.groupdocs.comparison.Comparer;
import com.groupdocs.comparison.options.WordCompareOptions;
// ...

try (Comparer comparer = new Comparer("source.docx")) {
    comparer.add("target.docx");

    WordCompareOptions options = new WordCompareOptions();
    options.setDisplayMode(WordCompareOptions.ComparisonDisplayMode.HIGHLIGHT);

    comparer.compare("result.docx", options);
}

The result:

Highlight mode

Detect style changes

Call setDetectStyleChanges(true) to include formatting differences (bold, font size, colour, etc.) alongside textual edits.

try (Comparer comparer = new Comparer("source.docx")) {
    comparer.add("target.docx");

    WordCompareOptions options = new WordCompareOptions();
    options.setDisplayMode(WordCompareOptions.ComparisonDisplayMode.REVISIONS);
    options.setDetectStyleChanges(true);

    comparer.compare("result.docx", options);
}

Compare headers and footers

Call setHeaderFootersComparison(true) to include header and footer content in the comparison.

try (Comparer comparer = new Comparer("source.docx")) {
    comparer.add("target.docx");

    WordCompareOptions options = new WordCompareOptions();
    options.setHeaderFootersComparison(true);

    comparer.compare("result.docx", options);
}

Mark line breaks

Call setMarkLineBreaks(true) to visually mark paragraph (line) breaks that differ between documents.

try (Comparer comparer = new Comparer("source.docx")) {
    comparer.add("target.docx");

    WordCompareOptions options = new WordCompareOptions();
    options.setMarkLineBreaks(true);

    comparer.compare("result.docx", options);
}

Other Word-specific properties

The properties below are also available on WordCompareOptions. Several of them are documented in dedicated articles — follow the links for details:

All CompareOptions base properties — InsertedItemStyle, DeletedItemStyle, ChangedItemStyle, SensitivityOfComparison, GenerateSummaryPage, and others — are also available on WordCompareOptions.

Note
The Word-specific setters on CompareOptions (setWordTrackChanges(), setCompareBookmarks(), setRevisionAuthorName(), and others) are deprecated. They keep working for backward compatibility, but new code should use WordCompareOptions. On a WordCompareOptions object, setWordTrackChanges(true) is equivalent to setDisplayMode(REVISIONS) and setWordTrackChanges(false) to setDisplayMode(HIGHLIGHT).

See also

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.