DOCX Compare - VB Sample Code

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'
4
5Imports System
6
7Imports pdftron
8Imports pdftron.Common
9Imports pdftron.Office
10
11Module DOCXCompareTestVB
12 Dim pdfNetLoader As PDFNetLoader
13 Sub New()
14 pdfNetLoader = pdftron.PDFNetLoader.Instance()
15 End Sub
16
17 ' The following sample illustrates how to use the pdftron.Office.DOCXCompare utility
18 ' class to compare two MS Word (DOCX) documents and produce a new DOCX document
19 ' containing the differences between them as tracked changes.
20 '
21 ' This comparison is performed entirely within the PDFNet and has *no* external or
22 ' system dependencies -- Comparison results will be the same whether on Windows,
23 ' Linux or Android.
24 '
25 ' Please contact us if you have any questions.
26 Sub Main()
27 PDFNet.Initialize(PDFTronLicense.Key)
28 PDFNet.SetResourcesPath("../../../../../Resources")
29
30 Dim input_path As String = "../../../../TestFiles/"
31 Dim output_path As String = "../../../../TestFiles/Output/"
32
33 ' Provide your own original and revised versions of a DOCX document here.
34 Dim original_filename As String = "SYH_Letter.docx"
35 Dim revised_filename As String = "SYH_Letter_revision2.docx"
36 Dim output_filename As String = "SYH_Letter_changes.docx"
37
38 Try
39 Dim options As New DOCXCompareOptions()
40
41 ' Compare the two DOCX documents, writing the differences as tracked
42 ' changes into the output DOCX document.
43 Dim result As DOCXCompareResult = DOCXCompare.Compare(input_path + original_filename, input_path + revised_filename, output_path + output_filename, options)
44
45 ' And we're done!
46 If result.DifferencesDetected() Then
47 Console.WriteLine("Differences detected, saved to " + output_filename)
48 Else
49 Console.WriteLine("No difference detected")
50 End If
51 Catch ex As PDFNetException
52 Console.WriteLine(ex.Message)
53 Catch ex As Exception
54 MsgBox(ex.Message)
55 End Try
56
57 Console.WriteLine("Done.")
58
59 PDFNet.Terminate()
60 End Sub
61
62End Module
63
64
65

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales