CompareOffice
DOCX Compare
This is sample code for using Apryse SDK to compare two DOCX documents and produce an output DOCX document where the differences are recorded as tracked changes. The comparison runs entirely within the SDK with no external or system dependencies, producing identical results across Windows, Linux, macOS, and Android. Sample code is provided in Python, C++, C#, Java, Node.js (JavaScript), PHP, Python, Ruby, Go, Objective-C, and VB.
Implementation steps
To compare DOCX files with Apryse Server SDK:
Step 1: Follow get started with Server SDK in your preferred language or framework. Step 2: Add the sample code provided in this guide.
Learn more about Apryse Server SDK.
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------
using System;
using pdftron;
using pdftron.Common;
using pdftron.Office;
//---------------------------------------------------------------------------------------
// The following sample illustrates how to use the pdftron.Office.DOCXCompare utility
// class to compare two MS Word (DOCX) documents and produce a new DOCX document
// containing the differences between them as tracked changes.
//
// This comparison is performed entirely within the PDFNet and has *no* external or
// system dependencies -- Comparison results will be the same whether on Windows,
// Linux or Android.
//
// Please contact us if you have any questions.
//---------------------------------------------------------------------------------------
namespace DOCXCompareTestCS
{
class Class1
{
private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
static Class1() {}
static string input_path = "../../../../TestFiles/";
static string output_path = "../../../../TestFiles/Output/";
// Provide your own original and revised versions of a DOCX document here.
static string original_filename = "SYH_Letter.docx";
static string revised_filename = "SYH_Letter_revision2.docx";
static string output_filename = "SYH_Letter_changes.docx";
/// <summary>
/// The following sample illustrates how to compare two DOCX documents using 'pdftron.Office.DOCXCompare'.
/// </summary>
static void Main(string[] args)
{
PDFNet.Initialize(PDFTronLicense.Key);
PDFNet.SetResourcesPath("../../../../../Resources");
try
{
DOCXCompareOptions options = new DOCXCompareOptions();
// Compare the two DOCX documents, writing the differences as tracked
// changes into the output DOCX document.
DOCXCompareResult result = DOCXCompare.Compare(input_path + original_filename, input_path + revised_filename, output_path + output_filename, options);
// And we're done!
if (result.DifferencesDetected())
{
Console.WriteLine("Differences detected, saved to " + output_filename);
}
else
{
Console.WriteLine("No difference detected");
}
}
catch (PDFNetException e)
{
Console.WriteLine(e.Message);
}
Console.WriteLine("Done.");
PDFNet.Terminate();
}
}
}