> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/core/get-started/samples/docxcomparetest.md).

# DOCX Compare

Sample code for using Apryse SDK to perform semantic comparison on docx files, recording differences as tracked changes. Sample code provided in Python, C++, C#, Java, Node.js (JavaScript), PHP, Ruby

{% hint style="info" %}
**Requirements**

*These packages are required to use these features in production. Trial keys have unlimited access to all features*

<a href="https://apryse.com/capabilities#Compare" class="button primary">Package: Compare</a>
{% endhint %}

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](/core/get-started/get-started.md). Step 2: Add the sample code provided in this guide.

Learn more about Apryse [Server SDK](/core/get-started/get-started.md).

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
//---------------------------------------------------------------------------------------
// 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();
		}
	}
}


```

{% endcode %}
{% endtab %}

{% tab title="Go" %}
{% code lineNumbers="true" %}

```go
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
// Consult LICENSE.txt regarding license information.
//---------------------------------------------------------------------------------------

package main
import (
        "fmt"
        "testing"
        "flag"
        . "github.com/pdftron/pdftron-go/v2"
)

var licenseKey string
var modulePath string

func init() {
    flag.StringVar(&licenseKey, "license", "", "License key for Apryse SDK")
    flag.StringVar(&modulePath, "modulePath", "", "Module path for Apryse SDK")
}

//------------------------------------------------------------------------------
// The following sample illustrates how to use the 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.
//------------------------------------------------------------------------------

// Relative path to the folder containing the test files.
var inputPath = "../TestFiles/"
var outputPath = "../TestFiles/Output/"

// Provide your own original and revised versions of a DOCX document here.
var originalFilename = "SYH_Letter.docx"
var revisedFilename = "SYH_Letter_revision2.docx"
var outputFilename = "SYH_Letter_changes.docx"

func TestDOCXCompare(t *testing.T){
    // The first step in every application using PDFNet is to initialize the
    // library. The library is usually initialized only once, but calling
    // Initialize() multiple times is also fine.
    PDFNetInitialize(licenseKey)
    PDFNetSetResourcesPath("../../Resources")

    options := NewDOCXCompareOptions()

    // Compare the two DOCX documents, writing the differences as tracked
    // changes into the output DOCX document.
    result := DOCXCompareCompare(inputPath + originalFilename, inputPath + revisedFilename, outputPath + outputFilename, options)

    // And we're done!
    if result.DifferencesDetected() {
        fmt.Println("Differences detected, saved to " + outputFilename)
    } else {
        fmt.Println("No difference detected")
    }

    PDFNetTerminate()
    fmt.Println("Done.")
}


```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

import com.pdftron.common.PDFNetException;
import com.pdftron.office.DOCXCompare;
import com.pdftron.office.DOCXCompareOptions;
import com.pdftron.office.DOCXCompareResult;
import com.pdftron.pdf.PDFNet;

//---------------------------------------------------------------------------------------
// The following sample illustrates how to use the 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.
//---------------------------------------------------------------------------------------
public class DOCXCompareTest {

    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";

    public 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);

            if (result.differencesDetected()) {
                System.out.println("Differences detected, saved to " + output_filename);
            }
            else {
                System.out.println("No difference detected");
            }
        }
        catch (PDFNetException e) {
            e.printStackTrace();
            System.out.println(e);
        }

        // And we're done!
        System.out.println("Done.");

        PDFNet.terminate();
    }

}


```

{% endcode %}
{% endtab %}

{% tab title="C++" %}
{% code lineNumbers="true" %}

```cpp
//------------------------------------------------------------------------------
// Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//------------------------------------------------------------------------------

#include <iostream>
#include <PDF/PDFNet.h>
#include <Office/DOCXCompare.h>
#include "../../LicenseKey/CPP/LicenseKey.h"

//------------------------------------------------------------------------------
// The following sample illustrates how to use the 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.
//------------------------------------------------------------------------------

using namespace pdftron;
using namespace Office;

UString input_path = "../../TestFiles/";
UString output_path = "../../TestFiles/Output/";

int main(int argc, char *argv[])
{
	// The first step in every application using PDFNet is to initialize the
	// library. The library is usually initialized only once, but calling
	// Initialize() multiple times is also fine.
	int ret = 0;

	PDFNet::Initialize(LicenseKey);
	PDFNet::SetResourcesPath("../../../Resources");

	// Provide your own original and revised versions of a DOCX document here.
	UString original_filename = "SYH_Letter.docx";
	UString revised_filename = "SYH_Letter_revision2.docx";
	UString output_filename = "SYH_Letter_changes.docx";

	try
	{
		DOCXCompareOptions options;

		// 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);

		if (result.DifferencesDetected())
		{
			std::cout << "Differences detected, saved to " << output_filename << std::endl;
		}
		else
		{
			std::cout << "No difference detected" << std::endl;
		}
	}
	catch (Common::Exception& e)
	{
		std::cout << e << std::endl;
		ret = 1;
	}
	catch (...)
	{
		std::cout << "Unknown Exception" << std::endl;
		ret = 1;
	}

	PDFNet::Terminate();
	std::cout << "Done.\n";
	return ret;
}


```

{% endcode %}
{% endtab %}

{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// The following sample illustrates how to use the PDFNet.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.
//------------------------------------------------------------------------------

const { PDFNet } = require('../../lib/pdfnet.js');
const PDFTronLicense = require('../../LicenseKey/NODEJS/LicenseKey');

((exports) => {

    exports.runDOCXCompareTest = () => {

        const main = async() => {
            // Relative paths to folders containing test files.
            const inputPath = '../TestFiles/';
            const outputPath = '../TestFiles/Output/';

            // Provide your own original and revised versions of a DOCX document here.
            const originalFilename = 'SYH_Letter.docx';
            const revisedFilename = 'SYH_Letter_revision2.docx';
            const outputFilename = 'SYH_Letter_changes.docx';

            try {
                const options = await PDFNet.DOCXCompare.createDOCXCompareOptions();

                // Compare the two DOCX documents, writing the differences as tracked
                // changes into the output DOCX document.
                const result = await PDFNet.DOCXCompare.compare(
                    inputPath + originalFilename,
                    inputPath + revisedFilename,
                    outputPath + outputFilename,
                    options
                );

                // And we're done!
                if (await result.differencesDetected()) {
                    console.log('Differences detected, saved to ' + outputFilename);
                } else {
                    console.log('No difference detected');
                }
            } catch (err) {
                console.log(err.stack);
            }

            console.log('Done.');
        };
        PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error){console.log('Error: ' + JSON.stringify(error));}).then(function(){return PDFNet.shutdown();});
    };
    exports.runDOCXCompareTest();
})(exports);
// eslint-disable-next-line spaced-comment
//# sourceURL=DOCXCompareTest.js


```

{% endcode %}
{% endtab %}

{% tab title="Python" %}
{% code lineNumbers="true" %}

```python
#---------------------------------------------------------------------------------------
# Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
# Consult LICENSE.txt regarding license information.
#---------------------------------------------------------------------------------------

import site
site.addsitedir("../../../PDFNetC/Lib")
import sys
from PDFNetPython import *

sys.path.append("../../LicenseKey/PYTHON")
from LicenseKey import *

# Relative path to the folder containing the test files.
input_path = "../../TestFiles/"
output_path = "../../TestFiles/Output/"

# Provide your own original and revised versions of a DOCX document here.
original_filename = "SYH_Letter.docx"
revised_filename = "SYH_Letter_revision2.docx"
output_filename = "SYH_Letter_changes.docx"

#---------------------------------------------------------------------------------------
# The following sample illustrates how to use the 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.
#---------------------------------------------------------------------------------------

def main():
    # The first step in every application using PDFNet is to initialize the
    # library. The library is usually initialized only once, but calling
    # Initialize() multiple times is also fine.
    PDFNet.Initialize(LicenseKey)
    PDFNet.SetResourcesPath("../../../Resources")

    try:
        options = DOCXCompareOptions()

        # Compare the two DOCX documents, writing the differences as tracked
        # changes into the output DOCX document.
        result = DOCXCompare.Compare(input_path + original_filename, input_path + revised_filename, output_path + output_filename, options)

        # And we're done!
        if result.DifferencesDetected():
            print("Differences detected, saved to " + output_filename)
        else:
            print("No difference detected")
    except Exception as e:
        print("Unable to compare DOCX documents, error: " + str(e))

    PDFNet.Terminate()
    print("Done.")

if __name__ == '__main__':
    main()


```

{% endcode %}
{% endtab %}

{% tab title="PHP" %}
{% code lineNumbers="true" %}

```php
<?php
//------------------------------------------------------------------------------
// Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//------------------------------------------------------------------------------
if(file_exists("../../../PDFNetC/Lib/PDFNetPHP.php"))
include("../../../PDFNetC/Lib/PDFNetPHP.php");
include("../../LicenseKey/PHP/LicenseKey.php");

// Relative path to the folder containing the test files.
$input_path = getcwd()."/../../TestFiles/";
$output_path = $input_path."Output/";

// Provide your own original and revised versions of a DOCX document here.
$original_filename = "SYH_Letter.docx";
$revised_filename = "SYH_Letter_revision2.docx";
$output_filename = "SYH_Letter_changes.docx";

//------------------------------------------------------------------------------
// The following sample illustrates how to use the 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.
//------------------------------------------------------------------------------

function main()
{
        global $input_path, $output_path, $original_filename, $revised_filename, $output_filename;

        // The first step in every application using PDFNet is to initialize the
        // library. The library is usually initialized only once, but calling
        // Initialize() multiple times is also fine.
        global $LicenseKey;
        PDFNet::Initialize($LicenseKey);
        PDFNet::SetResourcesPath("../../../Resources");

        try
        {
                $options = new DOCXCompareOptions();

                // Compare the two DOCX documents, writing the differences as tracked
                // changes into the output DOCX document.
                $result = DOCXCompare::Compare($input_path.$original_filename, $input_path.$revised_filename, $output_path.$output_filename, $options);

                // And we're done!
                if($result->DifferencesDetected())
                {
                        echo nl2br("Differences detected, saved to ".$output_filename."\n");
                }
                else
                {
                        echo nl2br("No difference detected\n");
                }
        }
        catch(Exception $e)
        {
                echo nl2br("Unable to compare DOCX documents, error: ".$e->getMessage()."\n");
        }

        PDFNet::Terminate();
        echo(nl2br("Done.\n"));
}

main()

?>


```

{% endcode %}
{% endtab %}

{% tab title="Ruby" %}
{% code lineNumbers="true" %}

```ruby
#---------------------------------------------------------------------------------------
# Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
# Consult LICENSE.txt regarding license information.
#---------------------------------------------------------------------------------------

require '../../../PDFNetC/Lib/PDFNetRuby'
include PDFNetRuby
require '../../LicenseKey/RUBY/LicenseKey'

$stdout.sync = true

#---------------------------------------------------------------------------------------
# The following sample illustrates how to use the 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.
#---------------------------------------------------------------------------------------

# Relative path to the folder containing the test files.
$inputPath = "../../TestFiles/"
$outputPath = "../../TestFiles/Output/"

# Provide your own original and revised versions of a DOCX document here.
$original_filename = "SYH_Letter.docx"
$revised_filename = "SYH_Letter_revision2.docx"
$output_filename = "SYH_Letter_changes.docx"

def main()
    # The first step in every application using PDFNet is to initialize the
    # library. The library is usually initialized only once, but calling
    # Initialize() multiple times is also fine.
    PDFNet.Initialize(PDFTronLicense.Key)
    PDFNet.SetResourcesPath("../../../Resources")

    begin
        options = DOCXCompareOptions.new()

        # Compare the two DOCX documents, writing the differences as tracked
        # changes into the output DOCX document.
        result = DOCXCompare.Compare($inputPath + $original_filename, $inputPath + $revised_filename, $outputPath + $output_filename, options)

        # And we're done!
        if result.DifferencesDetected()
            puts "Differences detected, saved to " + $output_filename
        else
            puts "No difference detected"
        end
    rescue => error
        puts "Unable to compare DOCX documents, error: " + error.message
    end

    PDFNet.Terminate
    puts "Done."
end

main()


```

{% endcode %}
{% endtab %}

{% tab title="VB" %}
{% code lineNumbers="true" %}

```vb
'
' Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
'

Imports System

Imports pdftron
Imports pdftron.Common
Imports pdftron.Office

Module DOCXCompareTestVB
    Dim pdfNetLoader As PDFNetLoader
    Sub New()
        pdfNetLoader = pdftron.PDFNetLoader.Instance()
    End Sub

    ' 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.
    Sub Main()
        PDFNet.Initialize(PDFTronLicense.Key)
        PDFNet.SetResourcesPath("../../../../../Resources")

        Dim input_path As String = "../../../../TestFiles/"
        Dim output_path As String = "../../../../TestFiles/Output/"

        ' Provide your own original and revised versions of a DOCX document here.
        Dim original_filename As String = "SYH_Letter.docx"
        Dim revised_filename As String = "SYH_Letter_revision2.docx"
        Dim output_filename As String = "SYH_Letter_changes.docx"

        Try
            Dim options As New DOCXCompareOptions()

            ' Compare the two DOCX documents, writing the differences as tracked
            ' changes into the output DOCX document.
            Dim result As DOCXCompareResult = DOCXCompare.Compare(input_path + original_filename, input_path + revised_filename, output_path + output_filename, options)

            ' And we're done!
            If result.DifferencesDetected() Then
                Console.WriteLine("Differences detected, saved to " + output_filename)
            Else
                Console.WriteLine("No difference detected")
            End If
        Catch ex As PDFNetException
            Console.WriteLine(ex.Message)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        Console.WriteLine("Done.")

        PDFNet.Terminate()
    End Sub

End Module



```

{% endcode %}
{% endtab %}

{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

```objc
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

#import <OBJC/PDFNetOBJC.h>
#import <Foundation/Foundation.h>

//------------------------------------------------------------------------------
// The following sample illustrates how to use the PTDOCXCompare 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.
//------------------------------------------------------------------------------

int main(int argc, char *argv[])
{

    @autoreleasepool {

        [PTPDFNet Initialize: 0];

        NSString *input_path = @"../../TestFiles/";
        NSString *output_path = @"../../TestFiles/Output/";
        // Provide your own original and revised versions of a DOCX document here.
        NSString *original_filename = @"SYH_Letter.docx";
        NSString *revised_filename = @"SYH_Letter_revision2.docx";
        NSString *output_filename = @"SYH_Letter_changes.docx";

        // Compare the two DOCX documents, writing the differences as tracked
        // changes into the output DOCX document.
        PTDOCXCompareOptions *options = [[PTDOCXCompareOptions alloc] init];
        PTDOCXCompareResult *result = [PTDOCXCompare Compare: [NSString stringWithFormat:@"%@%@", input_path, original_filename]
                              revised_docx_path: [NSString stringWithFormat:@"%@%@", input_path, revised_filename]
                                    output_path: [NSString stringWithFormat:@"%@%@", output_path, output_filename]
                                        options: options];

        if ([result DifferencesDetected]) {
            NSLog(@"Differences detected, saved to %@\n", output_filename);
        } else {
            NSLog(@"No difference detected\n");
        }
        NSLog(@"Done.\n");

        [PTPDFNet Terminate: 0];
        return 0;
    }
}


```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/core/get-started/samples/docxcomparetest.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
