When working with multiple versions of contracts, research papers, or technical documents, being able to compare Word documents is essential. With automated tools, you can compare 2 Word docs, highlight differences, and generate a comprehensive report showing insertions, deletions, or modifications. This ensures accuracy, saves time, and avoids manual review errors.

API for Word Document Comparison

The enables developers to easily compare Word files in their C# applications. This powerful API identifies text, formatting, and structural differences between Word documents. Install the SDK from NuGet:

NuGet\Install-Package GroupDocs.Comparison-Cloud -Version 23.10.0

Now, obtain your Client ID and Secret from GroupDocs cloud Dashboard.

Compare Word Documents using C#

Here’s how you can programmatically compare DOCX files using GroupDocs.Comparison:

  1. Configure API credentials:
var config = new Configuration(clientId, clientSecret);
  1. Initialize CompareApi:
var compareApi = new CompareApi(config);
  1. Define source and target Word files:
var sourceFile = new FileInfo("source.docx");
var targetFile = new FileInfo("target.docx");
  1. Create a comparison request:
var request = new ComparisonRequest(sourceFile, targetFile, outputPath);
  1. Call API to compare documents online:
var response = compareApi.Compare(request);

Compare DOCX Files via cURL

Alternatively, you can compare DOCX files online using and cURL commands. This is useful for automated scripts and CI/CD workflows.

  1. Generate JWT token:
curl -v "https://api.groupdocs.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=CLIENT_ID&client_secret=CLIENT_SECRET" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
  1. Perform Document Comparison:
curl -v -X POST "https://api.groupdocs.cloud/v2.0/comparison/comparisons" \
-H  "accept: application/json" \
-H  "authorization: Bearer {ACCESS_TOKEN}" \
-H  "Content-Type: application/json" \
-d "{  \"SourceFile\": {    \"FilePath\": \"firstDoc.docx\"  },  \"TargetFiles\": [    {      \"FilePath\": \"secondDoc.docx\"    }  ],  \"Settings\": {    \"GenerateSummaryPage\": true,    \"ShowDeletedContent\": true,    \"ShowInsertedContent\": true,    \"StyleChangeDetection\": true,    \"InsertedItemsStyle\": {      \"Bold\": true,      \"Italic\": true,      \"StrikeThrough\": true,      \"Underline\": true    },    \"DeletedItemsStyle\": {      \"Bold\": true,      \"Italic\": true,      \"StrikeThrough\": true,      \"Underline\": true    },    \"ChangedItemsStyle\": {      \"Bold\": true,      \"Italic\": true,      \"StrikeThrough\": true,      \"Underline\": true    },    \"WordsSeparatorChars\": [      \"string\"    ],    \"UseFramesForDelInsElements\": true,    \"CalculateComponentCoordinates\": true,    \"MarkChangedContent\": true,    \"MarkNestedContent\": true,    \"MetaData\": {      \"Author\": \"Nayyer Shahbaz\",      \"LastSaveBy\": \"Nayyer\",      \"Company\": \"GroupDocs Cloud\"    },    \"DiagramMasterSetting\": {      \"UseSourceMaster\": true    },    \"OriginalSize\": {      \"Width\": 0,      \"Height\": 0    },    \"HeaderFootersComparison\": true,    \"SensitivityOfComparison\": 0  },  \"OutputPath\": \"comparisonOutput.docx\"}"

Try Free Online Word Comparison Tool

Explore our free Document Comparison App to identify the differences between two DOCX files online without installing any software.

document comparison app

Final Comments

Using GroupDocs.Comparison Cloud SDK for .NET or cURL, you can easily compare 2 documents in Word and highlight differences. Whether you need to compare Word documents for legal, business, or academic use cases, this solution ensures accuracy and efficiency. Instead of relying on manual reviews or limited compare docs in Word features, you can integrate robust document comparison into your applications. This makes it simple to compare Word files, track revisions, and ensure document integrity.