Compare Documents

This demo uses the DevExpress Word Processing Document API to compare two Word documents. You can compare predefined sample files or supply your own documents. To do the latter, select Upload a File in the file selection drop-down menu.

Select the comparison level, settings, and the revision author. Use the Compare Documents and Save as… dropdown button to select the output format, compare documents, and download the result. The result is a document with revisions that indicate differences between the first and second documents.

Select a Document
Sample.docx
DocumentForProtection.docx
Press backspace or delete to remove the tag
Case Changes
Formatting
Headers and Footers
Textboxes



using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;

Stream CompareDocuments(Stream originalStream, Stream revisedStream, string author,
    bool compareCaseChanges, bool compareFormatting, bool compareHeadersFooters, bool compareTextBoxes,
    ComparisonLevel comparisonLevel, DocumentFormat outputFormat) {
    // Create document servers for comparison
    using var originalWordProcessor = new RichEditDocumentServer();
    using var revisedWordProcessor = new RichEditDocumentServer();

    // Load documents
    originalWordProcessor.LoadDocument(originalStream);
    revisedWordProcessor.LoadDocument(revisedStream);

    // Get documents for comparison
    var originalDoc = originalWordProcessor.Document;
    var revisedDoc = revisedWordProcessor.Document;

    CompareDocumentOptions options = new CompareDocumentOptions();
    options.CompareFormatting = compareFormatting;
    options.CompareCaseChanges = compareCaseChanges;
    options.CompareHeadersAndFooters = compareHeadersFooters;
    options.CompareTextBoxes = compareTextBoxes;
    options.ComparisonLevel = comparisonLevel;
    options.Author = author;
    options.DateTime = DateTime.Now;

    Document comparedDocument = originalDoc.Compare(revisedDoc, options);

    // Save the result document to a stream
    var outputStream = new MemoryStream();
    comparedDocument.SaveDocument(outputStream, outputFormat);
    outputStream.Position = 0;

    return outputStream;
}