DOCX Compare - Obj-C 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// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6#import <OBJC/PDFNetOBJC.h>
7#import <Foundation/Foundation.h>
8
9//------------------------------------------------------------------------------
10// The following sample illustrates how to use the PTDOCXCompare utility class
11// to compare two MS Word (DOCX) documents and produce a new DOCX document
12// containing the differences between them as tracked changes.
13//
14// This comparison is performed entirely within the PDFNet and has *no*
15// external or system dependencies -- Comparison results will be
16// the same whether on Windows, Linux or Android.
17//
18// Please contact us if you have any questions.
19//------------------------------------------------------------------------------
20
21int main(int argc, char *argv[])
22{
23
24 @autoreleasepool {
25
26 [PTPDFNet Initialize: 0];
27
28 NSString *input_path = @"../../TestFiles/";
29 NSString *output_path = @"../../TestFiles/Output/";
30 // Provide your own original and revised versions of a DOCX document here.
31 NSString *original_filename = @"SYH_Letter.docx";
32 NSString *revised_filename = @"SYH_Letter_revision2.docx";
33 NSString *output_filename = @"SYH_Letter_changes.docx";
34
35 // Compare the two DOCX documents, writing the differences as tracked
36 // changes into the output DOCX document.
37 PTDOCXCompareOptions *options = [[PTDOCXCompareOptions alloc] init];
38 PTDOCXCompareResult *result = [PTDOCXCompare Compare: [NSString stringWithFormat:@"%@%@", input_path, original_filename]
39 revised_docx_path: [NSString stringWithFormat:@"%@%@", input_path, revised_filename]
40 output_path: [NSString stringWithFormat:@"%@%@", output_path, output_filename]
41 options: options];
42
43 if ([result DifferencesDetected]) {
44 NSLog(@"Differences detected, saved to %@\n", output_filename);
45 } else {
46 NSLog(@"No difference detected\n");
47 }
48 NSLog(@"Done.\n");
49
50 [PTPDFNet Terminate: 0];
51 return 0;
52 }
53}
54
55

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales