Get source and target text from files

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Comparison MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-comparison -- dnx GroupDocs.Comparison.Mcp --yes
Folders, licensing and more →

GroupDocs.Comparison allows you to get source and target texts of specific changes in the output file.

To get a list of changed source and target texts, follow these steps:

  1. Instantiate the Comparer object. Specify the source document path or stream.
  2. Call the Add method. Specify the target document path or stream.
  3. Call the Compare method.
  4. Call the GetChanges method.

The following code snippets show how to get specified texts from a file.

Get source and target text from local disk

using System;
using GroupDocs.Comparison;
using GroupDocs.Comparison.Result;
// ...

using (Comparer comparer = new Comparer("source.docx"))
{
    comparer.Add("target.docx");
    comparer.Compare("result.docx");
    ChangeInfo[] changes = comparer.GetChanges();
    foreach (ChangeInfo change in changes)
    {
        Console.WriteLine("");
        Console.WriteLine("Source text: " + change.SourceText);
        Console.WriteLine("Target text: " + change.TargetText);
    }
}

The result is as follows:

Get source and target text from stream

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

using (Comparer comparer = new Comparer(File.OpenRead("source.docx")))
{
    comparer.Add(File.OpenRead("target.docx"));
    comparer.Compare("result.docx");
    ChangeInfo[] changes = comparer.GetChanges();
    foreach (ChangeInfo change in changes)
    {
        Console.WriteLine("");
        Console.WriteLine("Source text: " + change.SourceText);
        Console.WriteLine("Target text: " + change.TargetText);
    }
}