# Document Comparison

> Compare documents with TX Text Control: paragraph comparison with ServerTextControl, word and image comparison samples and tracked changes on the server.

- **Product:** TX Text Control .NET Server
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET Server > Document Processing > Document Comparison
- **1994 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/document-processing/comparison/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/document-processing/comparison/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/document-processing/comparison/llms-full.txt

---

Which paragraphs of a contract changed between two versions? TX Text Control .NET Server has no method that compares two documents, but its API provides the building blocks for it. The approaches that Text Control describes differ in what they find and in the engine they need. For a document that was compared in MS Word or reviewed in the Document Editor, your code processes its tracked changes on the server.

Tracked changes in the browser are the subject of [Track Changes](https://docs.textcontrol.com/tx-text-control-dotnet-server/document-editor/track-changes/llms-full.txt) in the Document Editor section and [Tracked Changes](https://docs.textcontrol.com/tx-text-control-dotnet-server/document-viewer/tracked-changes/llms-full.txt) in the Document Viewer section.

### Approaches to Comparing Documents

| Approach | Finds | Where it is described |
|---|---|---|
| Compare the text of paragraphs | Paragraphs whose text differs | The example below, built from `ServerTextControl` members |
| Compare words and mark the differences as tracked changes | Inserted and deleted words | A Windows Forms sample of the Text Control blog |
| Compare rendered pages as images | Visual differences, such as changed fonts, alignment or colors | A sample of the Text Control blog that uses the Classic engine |

### Compare the Text of Paragraphs

`ServerTextControl` loads both documents one after the other, and the text of their paragraphs is compared. The following program prints the paragraphs of *Documents/original.docx* and *Documents/revised.docx* that differ:

```csharp
using TXTextControl;

List<string> originalParagraphs;
List<string> revisedParagraphs;

using (ServerTextControl tx = new ServerTextControl())
{
    tx.Create();

    tx.Load("Documents/original.docx", StreamType.WordprocessingML);
    originalParagraphs = GetParagraphTexts(tx);

    // Loading the second document replaces the first one
    tx.Load("Documents/revised.docx", StreamType.WordprocessingML);
    revisedParagraphs = GetParagraphTexts(tx);
}

int count = Math.Max(originalParagraphs.Count, revisedParagraphs.Count);

for (int i = 0; i < count; i++)
{
    string original = i < originalParagraphs.Count ? originalParagraphs[i] : "(no paragraph)";
    string revised = i < revisedParagraphs.Count ? revisedParagraphs[i] : "(no paragraph)";

    if (original != revised)
    {
        Console.WriteLine($"Paragraph {i + 1} differs");
        Console.WriteLine($"  original: {original}");
        Console.WriteLine($"  revised:  {revised}");
    }
}

// Returns the text of every paragraph of the main text
static List<string> GetParagraphTexts(ServerTextControl tx)
{
    List<string> texts = new List<string>();

    foreach (Paragraph paragraph in tx.Paragraphs)
    {
        texts.Add(paragraph.Text.TrimEnd());
    }

    return texts;
}
```

The code works as follows:

- [Load](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/servertextcontrol/load-method/llms-full.txt) replaces the complete contents, so one instance reads both documents.
- [ServerTextControl.Paragraphs](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/servertextcontrol/paragraphs-property/llms-full.txt) contains the paragraphs of the main text, and [Paragraph.Text](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/paragraph/text-property/llms-full.txt) is the text of each.
- The paragraphs are paired by their position. When a paragraph is inserted or deleted in the revised document, all paragraphs after it are reported as different.

The comparison covers only the text of the paragraphs in the main text: formatting and the text of headers and footers aren't compared.

### Compare Words and Mark the Differences

The blog article [Word-based Document Comparison and Track Changes Using TX Text Control and C#](https://www.textcontrol.com/blog/2024/05/02/word-based-document-comparison-and-track-changes-using-tx-text-control-and-c-sharp/) compares two documents word by word. It walks through the paragraphs of both documents, splits them into sentences and words and marks each difference as a tracked change in the original document, so users review the result like a document edited with track changes. The article points out that this method has limitations.

![The window of the comparison sample: the revised text on the right, and on the left the original text with the replaced words struck through in red and the new words inserted and underlined.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-server/word-comparison-result.35764a04.webp)

Its sample, [TXTextControl.Windows.Forms.Comparison](https://github.com/TextControl/TXTextControl.Windows.Forms.Comparison), is a Windows Forms application. It turns on track changes with `TextControl.IsTrackChangesEnabled`, a member of the Windows Forms control that `ServerTextControl` doesn't have, so the sample can't create tracked changes on the server as it is. The class that records tracked changes on the server is named in [Record Changes on the Server](https://docs.textcontrol.com/tx-text-control-dotnet-server/document-processing/track-changes/#record-changes-on-the-server).

### Compare Pages as Images

The blog article [Document Comparison using Image-Based Pixel Matching in .NET C#](https://www.textcontrol.com/blog/2025/01/13/document-comparison-using-image-based-pixel-matching-in-net-csharp/) renders the pages of both documents as images and compares them pixel by pixel. This finds visual differences that a text comparison misses, such as a different font, alignment or color, and it reports which pages differ. When the documents have different numbers of pages, it stops and reports that.

In the article's example, the second version of a document has a smaller image on one page. The text of both versions is the same, but the page images differ, and the comparison reports the page:

![A page of the compared document with a photo below a paragraph; a red circle marks the corner of the image whose size was reduced in the second version.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-server/pixel-comparison-diff.1952f09b.webp)

Its sample, [TXTextControl.Compare.Pixel](https://github.com/TextControl/TXTextControl.Compare.Pixel), creates a bitmap of each page with [Page.GetImage](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/page/getimage-method/llms-full.txt) and compares the bitmaps with `System.Drawing`. It references the Classic package `TXTextControl.TextControl.ASP.SDK`.

### Process Tracked Changes on the Server

A document that was compared in MS Word, or edited with track changes in the Document Editor, contains its differences as tracked changes, each with its author and time. [ServerTextControl.TrackedChanges](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/servertextcontrol/trackedchanges-property/llms-full.txt) returns them, and [TrackedChangeCollection.Remove](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/trackedchangecollection/remove-method/llms-full.txt) accepts or rejects each one. [Track Changes](https://docs.textcontrol.com/tx-text-control-dotnet-server/document-processing/track-changes/llms-full.txt) lists the changes of a document, accepts and rejects them by author or by the decisions of a review and accepts all changes before a document is published.

### Next Steps

- [Track Changes](https://docs.textcontrol.com/tx-text-control-dotnet-server/document-processing/track-changes/llms-full.txt): accept and reject tracked changes on the server.
- [Track Changes](https://docs.textcontrol.com/tx-text-control-dotnet-server/document-editor/track-changes/llms-full.txt) in the Document Editor: let users review changes in the browser.
- [Pages](https://docs.textcontrol.com/tx-text-control-dotnet-server/document-processing/pages/llms-full.txt): render the pages of a document as images.
- [Paragraphs](https://docs.textcontrol.com/tx-text-control-dotnet-server/document-processing/paragraphs/llms-full.txt): read and format the paragraphs of a document.
- [Loading Documents](https://docs.textcontrol.com/tx-text-control-dotnet-server/document-processing/loading/llms-full.txt): load the documents you compare.

---

## Nearby

- **Previous:** [Pages](https://docs.textcontrol.com/tx-text-control-dotnet-server/document-processing/pages/llms-full.txt)
- **Next:** [Printing](https://docs.textcontrol.com/tx-text-control-dotnet-server/document-processing/printing/llms-full.txt)
