Compare Documents

Сompare documents and track changes like insertions, deletions, and modifications using C#.
What is this page about?
This page explains how to compare two documents using Wordize, detect insertions, deletions, and modifications, and generate a revision-style document highlighting those differences.
Supported Modules and Document Formats

Wordize supports comparison of documents in any format:

  • to compare documents, use the Wordize Comparison for .NET module
  • to work with documents in the required formats, select the appropriate document conversion module

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:

var doc1 = "Document1.docx";
var doc2 = "Document2.doc";

Comparer.Compare(doc1, doc2, "CompareDocuments.1.docx", "Author", new DateTime());
Important to note:

To compare documents, you will need the following Wordize modules with the corresponding licenses:

  1. The Wordize Comparison for .NET module, which provides functionality for comparing documents.
  2. The mandatory Wordize Core for .NET module, which allows users to load and save documents in Microsoft Word format. Without purchasing this module, none of the other modules will work.
  3. Optional: other document conversion module to work with the required formats. For example, to compare two HTML documents, you will also need the additional Wordize Web for .NET module.

Compare Documents and Save the Result as an Image

You can also compare two documents and save the result as an image using the CompareToImages method. 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);

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:

var doc1 = "Document1.docx";
var doc2 = "Document2.doc";

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

Comparer.Compare(doc1, doc2, "CompareDocuments.3.docx", "Author", new DateTime(), compareOptions);

See Also

FAQ

  1. Q: Which Wordize modules and licenses do I need to use the comparison feature?
    A: You must have the Wordize Core for .NET module (required for any document handling) and the Wordize Comparison for .NET module (provides the Compare API). If you compare documents in formats other than DOC/DOCX, add the appropriate document conversion module (e.g., Wordize Web for .NET for HTML).

  2. Q: How are the differences presented in the output document?
    A: The comparison creates revision marks in the first (base) document. Insertions appear as added text, deletions are shown as removed text, and modifications are displayed as a combination of both, allowing you to review changes directly in Word.

  3. Q: Can I ignore specific elements such as case changes, tables, or headers during comparison?
    A: Yes. Create a CompareOptions object and set the desired flags (e.g., IgnoreCaseChanges, IgnoreTables, IgnoreHeadersAndFooters). Pass this object to Comparer.Compare to tailor the comparison.

  4. Q: Is it possible to compare documents that are not DOCX or DOC, such as HTML or PDF?
    A: Absolutely. Wordize can compare any supported format, but you need the corresponding conversion module for those formats (e.g., Wordize Web for .NET for HTML). Once the modules are installed, use the same Comparer.Compare method with the file paths.

  5. Q: How do I export the comparison result as images instead of a Word document?
    A: Use the Comparer.CompareToImages method. It returns an array of Stream objects, each representing a page rendered as an image. You can specify the image format with ImageSaveOptions, for example SaveFormat.Png.