Compare Documents

Сompare documents and track changes like insertions, deletions, and modifications using C#.

Go to Comparison Code Examples

Wordize provides an easy and efficient way to compare two documents and highlight their differences. This feature helps track changes between document versions, whether for collaboration, version control, or content auditing.

With the Wordize Comparison for .NET, you can programmatically compare two documents and generate a document with the detected changes. The comparison results include insertions, deletions, and modifications, making it easy to review document differences.

How to Compare Documents

When comparing documents, differences between the second and first documents are displayed as revisions in the first document – each detected change will have its revision.

The comparison functionality in Wordize is accessible through the Comparer class, which provides the Compare methods for comparing documents.

The following code example shows how to compare DOCX and DOC documents:

string firstDoc = "Document1.docx";
string secondDoc = "Document2.doc";

Comparer.Compare(firstDoc, secondDoc, "CompareDocuments.1.docx", "Author", new DateTime());

Find a full list of code examples of comparing documents in the Comparison Code Examples section at the bottom of the page.

Compare Documents and Save the Result as an Image

You can also compare two documents and save the result as an image. In this case, each element of the returned array represents a single page of the output, rendered as an image.

The following code example shows how to compare two DOCX documents and save the result as a PNG:

Stream[] pages = Comparer.CompareToImages("Document1.docx", "Document2.docx", new ImageSaveOptions(SaveFormat.Png), "Wordize", Datetime.Now);

Find a full list of code examples of comparing documents in the Comparison Code Examples section at the bottom of the page.

Compare Documents Using Comparison Options

For a more precise comparison, you can use CompareOptions:

  • CompareMoves – specifies whether to compare the differences between two documents and present the differences as a move revision, defaults to “false”
  • IgnoreCaseChanges – specifies no case sensitivity, defaults to “true”
  • IgnoreTables – specifies whether to ignore data in tables when comparing, defaults to “false”
  • IgnoreFields – specifies whether to ignore data in fields when comparing, defaults to “false”.
  • IgnoreFootnotes – specifies whether to ignore data in footnotes and endnotes when comparing, defaults to “false”.
  • IgnoreComments – specifies whether to ignore data in comments when comparing, defaults to “false”.
  • IgnoreTextboxes – specifies whether to ignore data in text boxes when comparing, defaults to “false”.
  • IgnoreFormatting – specifies whether to ignore formatting when comparing, defaults to “false”.
  • IgnoreHeadersAndFooters – specifies whether to ignore data in headers and footers when comparing, defaults to “false”.
  • Granularity – specifies whether changes are tracked by characters or by words, defaults to “WordLevel”

The following code example shows how to compare DOCX and DOC documents, using IgnoreCaseChanges option:

string firstDoc = "Document1.docx";
string secondDoc = "Document2.doc";

CompareOptions compareOptions = new CompareOptions();
compareOptions.IgnoreCaseChanges =true;

Comparer.Compare(firstDoc, secondDoc, "CompareDocuments.3.docx", "Author", new DateTime(), compareOptions);

Find a full list of code examples of comparing documents with options in the next Comparison Code Examples section.

Comparison Code Examples

Wordize provides both a Standard API and a Fluent API, allowing developers to choose the most convenient approach for their needs.

Go to Comparison description

Wordize API

The following code examples show how to compare documents, specifying comparison options and using one of the Compare methods.


method Compare(string, string, string, string, DateTime)
string firstDoc = "Document1.docx";
string secondDoc = "Document2.doc";

Comparer.Compare(firstDoc, secondDoc, "CompareDocuments.1.docx", "Author", new DateTime());

method Compare(string, string, string, SaveFormat, string, DateTime)
string firstDoc = "Document1.docx";
string secondDoc = "Document2.doc";

Comparer.Compare(firstDoc, secondDoc, "CompareDocuments.2.docx", SaveFormat.Docx, "Author", new DateTime());

method Compare(Stream, Stream, Stream, SaveFormat, string, DateTime)
using var firstStreamIn = File.OpenRead("Document1.docx");
using var secondStreamIn = File.OpenRead("Document2.docx");
using var streamOut = File.Create("CompareStreamDocuments.1.docx");

Comparer.Compare(firstStreamIn, secondStreamIn, streamOut, SaveFormat.Docx, "Author", new DateTime());

method Compare(string, string, string, string, DateTime, CompareOptions)
string firstDoc = "Document1.docx";
string secondDoc = "Document2.doc";

CompareOptions compareOptions = new CompareOptions();
compareOptions.IgnoreCaseChanges =true;

Comparer.Compare(firstDoc, secondDoc, "CompareDocuments.3.docx", "Author", new DateTime(), compareOptions);

method Compare(string, string, string, SaveFormat, string, DateTime, CompareOptions)
string firstDoc = "Document1.docx";
string secondDoc = "Document2.doc";

CompareOptions compareOptions = new CompareOptions();
compareOptions.IgnoreCaseChanges =true;

Comparer.Compare(firstDoc, secondDoc, "CompareDocuments.4.docx", SaveFormat.Docx, "Author", new DateTime(), compareOptions);

method Compare(Stream, Stream, Stream, SaveFormat, string, DateTime, CompareOptions)
using var firstStreamIn = File.OpenRead("Document1.docx");
using var secondStreamIn = File.OpenRead("Document2.docx");
using var streamOut = File.Create("CompareStreamDocuments.2.docx");

CompareOptions compareOptions = new CompareOptions();
compareOptions.IgnoreCaseChanges = true;

Comparer.Compare(firstStreamIn, secondStreamIn, streamOut, SaveFormat.Docx, "Author", new DateTime(), compareOptions);

method CompareToImages(string, string, ImageSaveOptions, string, DateTime, CompareOptions)
Stream[] pages = Comparer.CompareToImages("Document1.docx", "Document2.docx", new ImageSaveOptions(SaveFormat.Png), "Wordize", Datetime.Now);

method CompareToImages(Stream, Stream, ImageSaveOptions, string, DateTime, CompareOptions)
using var firstStreamIn = File.OpenRead("Document1.docx");
using var secondStreamIn = File.OpenRead("Document2.docx");

Stream[] pages = Comparer.CompareToImages(firstStreamIn, secondStreamIn, new ImageSaveOptions(SaveFormat.Png), "Wordize", Datetime.Now);

Wordize Fluent API

Within the Fluent API, there is a context. ComparerContext allows you to customize the document comparison process. Specify the following properties to add the context:

  • AcceptRevisions – specifies whether to accept revisions to documents before comparing them, defaults to “true”
  • Author – specifies the author to assign to revisions created during document comparison
  • CompareOptions – specifies the comparison options
  • DateTime – specifies the date and time assigned to revisions created during document comparison

You can compare documents with or without context.

Also, the Fluent API does not limit you in the number of input documents, but it is important to remember that you can only compare two documents.


method to Compare files and write the result to a file
string firstDoc = "Document1.docx";
string secondDoc = "Document2.doc";

Comparer.Create()
    .From(firstDoc)
    .From(secondDoc)
    .To("CompareDocuments.1.docx")
    .Execute();

method to Compare files and write the result to a file, specifying the output SaveFormat and context
string firstDoc = "Document1.docx";
string secondDoc = "Document2.doc";

ComparerContext comparerContext = new ComparerContext();
context.Author = "James Bond";

Comparer.Create(comparerContext)
    .From(firstDoc)
    .From(secondDoc)
    .To("CompareDocuments.2.docx", SaveFormat.Docx)
    .Execute();

method to Compare documents from streams and write the result to a stream, specifying the output SaveFormat
using var firstStreamIn = File.OpenRead("Document1.docx");
using var secondStreamIn = File.OpenRead("Document2.docx");
using var streamOut = File.Create("CompareStreamDocuments.1.docx");

Comparer.Create()
    .From(firstStreamIn)
    .From(secondStreamIn)
    .To(streamOut, SaveFormat.Docx)
    .Execute();

method to Compare files and write the result to a file, specifying the IgnoreCaseChanges comparison option
string firstDoc = "Document1.docx";
string secondDoc = "Document2.doc";

ComparerContext comparerContext = new ComparerContext();
comparerContext.CompareOptions.IgnoreCaseChanges = true;

Comparer.Create(comparerContext)
    .From(firstDoc)
    .From(secondDoc)
    .To("CompareDocuments.3.docx")
    .Execute();

method to Compare files and write the result to a file, specifying the output SaveFormat and the IgnoreCaseChanges comparison option as context
string firstDoc = "Document1.docx";
string secondDoc = "Document2.doc";

ComparerContext comparerContext = new ComparerContext();
comparerContext.CompareOptions.IgnoreFormatting = true;

Comparer.Create(comparerContext)
    .From(firstDoc)
    .From(secondDoc)
    .To("CompareDocuments.4.docx", SaveFormat.Docx)
    .Execute();

method to Compare documents from streams and write the result to a stream, specifying the output SaveFormat and the IgnoreCaseChanges comparison option
using var firstStreamIn = File.OpenRead("Document1.docx");
using var secondStreamIn = File.OpenRead("Document2.docx");
using var streamOut = File.Create("CompareStreamDocuments.2.docx");

ComparerContext comparerContext = new ComparerContext();
comparerContext.CompareOptions.IgnoreFormatting = true;

Comparer.Create(comparerContext)
    .From(firstStreamIn)
    .From(secondStreamIn)
    .To(streamOut, SaveFormat.Docx)
    .Execute();

method to Compare documents from files and save the result to an image

The result can be saved not only to a file or stream, but also to a list of streams. The latter is useful when saving the result as images, where each page of the document is saved as a separate stream and added to the list. In this case, you can also specify multiple output types at the same time.

List<Stream> outputStreams = new List<Stream>();

Comparer.Create()
    .From("Document1.docx")
    .From("Document2.docx")
    .To(outputStreams, new ImageSaveOptions(SaveFormat.Png)) // Note: a separate stream is created for each page. The streams disposing is the consumer responsibility.
    .Execute();

method to Compare documents from streams and save the result to an image
using var firstStreamIn = File.OpenRead("Document1.docx");
using var secondStreamIn = File.OpenRead("Document2.docx");

List<Stream> outputStreams = new List<Stream>();

Comparer.Create()
    .From(firstStreamIn)
    .From(secondStreamIn)
    .To(outputStreams, new ImageSaveOptions(SaveFormat.Png)) // Note: a separate stream is created for each page. The streams disposing is the consumer responsibility.
    .Execute();