DOCX Compare

Requirements

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.

1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6using System;
7
8using pdftron;
9using pdftron.Common;
10using pdftron.Office;
11
12//---------------------------------------------------------------------------------------
13// The following sample illustrates how to use the pdftron.Office.DOCXCompare utility
14// class to compare two MS Word (DOCX) documents and produce a new DOCX document
15// containing the differences between them as tracked changes.
16//
17// This comparison is performed entirely within the PDFNet and has *no* external or
18// system dependencies -- Comparison results will be the same whether on Windows,
19// Linux or Android.
20//
21// Please contact us if you have any questions.
22//---------------------------------------------------------------------------------------
23
24namespace DOCXCompareTestCS
25{
26 class Class1
27 {
28 private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
29 static Class1() {}
30
31 static string input_path = "../../../../TestFiles/";
32 static string output_path = "../../../../TestFiles/Output/";
33
34 // Provide your own original and revised versions of a DOCX document here.
35 static string original_filename = "SYH_Letter.docx";
36 static string revised_filename = "SYH_Letter_revision2.docx";
37 static string output_filename = "SYH_Letter_changes.docx";
38
39 /// <summary>
40 /// The following sample illustrates how to compare two DOCX documents using 'pdftron.Office.DOCXCompare'.
41 /// </summary>
42 static void Main(string[] args)
43 {
44 PDFNet.Initialize(PDFTronLicense.Key);
45 PDFNet.SetResourcesPath("../../../../../Resources");
46
47 try
48 {
49 DOCXCompareOptions options = new DOCXCompareOptions();
50
51 // Compare the two DOCX documents, writing the differences as tracked
52 // changes into the output DOCX document.
53 DOCXCompareResult result = DOCXCompare.Compare(input_path + original_filename, input_path + revised_filename, output_path + output_filename, options);
54
55 // And we're done!
56 if (result.DifferencesDetected())
57 {
58 Console.WriteLine("Differences detected, saved to " + output_filename);
59 }
60 else
61 {
62 Console.WriteLine("No difference detected");
63 }
64 }
65 catch (PDFNetException e)
66 {
67 Console.WriteLine(e.Message);
68 }
69
70 Console.WriteLine("Done.");
71
72 PDFNet.Terminate();
73 }
74 }
75}
76
77

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales