Compare documents

GroupDocs.Comparison detects changes in text (paragraphs, words, characters), tables, images, and shapes across a wide range of formats — Word, PDF, Excel, PowerPoint, HTML, AutoCAD, Visio, Outlook, OpenDocument, images, and more. The full list is available on the Supported document formats page.

By default, GroupDocs.Comparison highlights detected changes with the following colours:

  • Inserted – blue
  • Deleted – red
  • Style changed – green

These are the defaults — you can override colours, fonts, and other styling via the InsertedItemStyle, DeletedItemStyle, and ChangedItemStyle properties. See Customize changes styles for details.

Basic comparison workflow

To compare two documents, follow these steps:

  1. Instantiate the Comparer object with the source document path or stream.
  2. Call the Add method and specify the target document path or stream.
  3. Call the Compare method.

Compare local documents

using GroupDocs.Comparison;
// ...

using (Comparer comparer = new Comparer("source.docx"))
{
    comparer.Add("target.docx");
    comparer.Compare("result.docx");
}

The output file is as follows:

Compare documents from stream

using GroupDocs.Comparison;
using System.IO;
// ...

using (Comparer comparer = new Comparer(File.OpenRead("source.docx")))
{
    comparer.Add(File.OpenRead("target.docx"));
    comparer.Compare(File.Create("result.docx"));
}

Customize comparison with options

To control how the comparison is performed and how the result is rendered, pass a CompareOptions object to the Compare method. These options work with any supported document format:

using GroupDocs.Comparison;
using GroupDocs.Comparison.Options;
// ...

using (Comparer comparer = new Comparer("source.docx"))
{
    comparer.Add("target.docx");

    CompareOptions options = new CompareOptions
    {
        DetectStyleChanges = true,
        GenerateSummaryPage = true,
        ShowDeletedContent = true,
        ShowInsertedContent = true
    };

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

For format-specific behaviour, GroupDocs.Comparison provides dedicated subclasses of CompareOptions:

Using a format-specific subclass is recommended when comparing a known document type — it makes Word-only or PDF-only settings discoverable and prevents you from passing irrelevant options.

Configure loading with LoadOptions

While CompareOptions controls how documents are compared, LoadOptions controls how the source and target files are loaded into the Comparer. It is passed to the Comparer constructor and to Add, before any comparison runs.

using GroupDocs.Comparison;
using GroupDocs.Comparison.Options;
// ...

LoadOptions loadOptions = new LoadOptions
{
    FileType = FileType.DOCX
};

using (Comparer comparer = new Comparer("source.docx", loadOptions))
{
    comparer.Add("target.docx", loadOptions);
    comparer.Compare("result.docx");
}

Common LoadOptions properties:

Next steps

Once the basic comparison works, common follow-up tasks include:

Close
Loading

Analyzing your prompt, please hold on...

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