Compare Word or PDF files using Swift SDK

Powerful Swift library to compare files in PDF, Word, HTML, TXT, MD and other formats

Use our Swift file difference checker, compare two documents and see the differences between them clearly shown in the output. You no longer need to compare your documents manually. Also note that the comparison result can be exported to a DOCX, PDF, DOC and others.

View code snippet

Comparing two files in Swift

Our Swift solution is designed to give you the best possible results when using a complex comparison algorithm. So, you no longer need to manually look up differences in documents – feel free to use our API to diff two files.

Our comparison engine looks for differences at the level of characters or whole words. And if only one character was changed, the whole word will be highlighted as changed. All found changes can be clearly viewed in the output and exported in a convenient format.

The most popular types of comparison are comparing PDF and Word files. Therefore, we will learn our Swift diff tool and its comparison function using these examples.

Compare PDF in Swift

Sometimes you need to make sure that your PDF document has not been modified and compare it with the original version. Or you already know that your PDF has really changed, and you need to look where and how. Then you can compare two versions of PDF files and see the differences. And to avoid doing it manually, just use our Swift diff checker API.

With our Swift solution, you will see even small changes that you could easily miss in a manual comparison.

Compare two Word documents using Swift

Word documents are fairly easy to change, so it is important to compare Word files to make sure parts or the entire document have not changed.

To compare Word files, use our Swift solution, just like with PDF. You can do this in the example below.

Сompare two documents

To see how our Swift document compare works, load two files you want to compare and choose an export file format.

After the comparison is completed, the document with the diff will be automatically downloaded in the format you selected.

It is important that the documents being compared must not have any revisions before the comparison, so we need to accept all revisions before the compare starts. Do not worry, we have taken care of that in our example:

Upload the compared file
Run code
Upload the second file to compare
Select the target format from the list
import AsposeWordsCloud

let config = 
    Configuration(clientId: "####-####-####-####-####", clientSecret: "##################");
let api = try WordsAPI(configuration: config);
let fileName1 = "Input1.docx";
let fileName2 = "Input2.docx";
let fileResult = "Output.docx";

//  Upload documents to cloud storage.
let firstDocumentContent = InputStream(url: URL(string: fileName1))!;
let uploadFirstFileRequest = 
    UploadFileRequest(fileContent: firstDocumentContent, path: fileName1);
_ = try api.uploadFile(request: uploadFirstFileRequest);

let secondDocumentContent = InputStream(url: URL(string: fileName2))!;
let uploadSecondFileRequest = 
    UploadFileRequest(fileContent: secondDocumentContent, path: fileName2);
_ = try api.uploadFile(request: uploadSecondFileRequest);

//  Compare documents in cloud.
let compareDataOptions = CompareData()
  .setAuthor(author: "author")
  .setComparingWithDocument(comparingWithDocument: fileName2);
let compareDocumentRequest = 
    CompareDocumentRequest(name: fileName1, compareData: compareDataOptions,
	destFileName: fileResult);
_ = try api.compareDocument(request: compareDocumentRequest);

//  Download result document from cloud storage.
let downloadFileRequest = DownloadFileRequest(path: fileResult);
let downloadFileResult = try api.downloadFile(request: downloadFileRequest);
try downloadFileResult?.first?.value.write(
    to: currentDir!.appendingPathComponent(fileResult, isDirectory: false));
Run code
  
Copy Swift code to the clipboard

How to Compare two versions of a file

  1. Install Aspose.Words Cloud for Swift
  2. Add a library reference (import the library) to your Swift project
  3. Load two documents to compare
  4. Call the compareDocument() method to compare two docs
  5. Download the result document from the cloud storage

Swift library to use compare

You can use Swift package manager and Cocoapods dependency manager to install Aspose.Words Cloud SDK for Swift. Detailed information on installing the package is given in the "Installation and Usage" section.

As an alternative, you can clone Aspose.Words Cloud SDK for Swift source code from GitHub and use it in your project.

Please follow these Instructions to quickly get the necessary security credentials and access our REST API.

System Requirements

Swift 4.2 or newer

Refer to the Repository Documentation to see more details.

Most popular formats for compare operations

5%

Subscribe to Aspose Product Updates

Get monthly newsletters and offers directly delivered to your mailbox.

© Aspose Pty Ltd 2001-2024. All Rights Reserved.