> 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/ios/compare-files/file-comparison-i.md).

# Compare PDF files on iOS

Enhance your file comparison capabilities with the Apryse SDK. Learn how to highlight differences between PDF pages and create customizable visual comparisons effortlessly. Explore the powerful featur

The Apryse SDK provides powerful file comparison functionality. An example of this capability is shown below by comparing two PDF pages and highlighting the difference between them in red.

| File 1                                                                                                                                                                                                                                            | File 2                                                                                                                                                                                                                                            | Difference                                                                                                                                                                                                                                        |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ![](https://4149080208-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgY6xtY9ZQd9XMpvWlGM0%2Fuploads%2Fgit-blob-a3fd7c34d0ff2a47e6601b447be105a324c06894%2Ffa37a99afc74d0f696f8e308cd3b454c8f31c321-1400x1314.png?alt=media) | ![](https://4149080208-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgY6xtY9ZQd9XMpvWlGM0%2Fuploads%2Fgit-blob-40d2ec0260cda7b9d3c91aa3c985c8ba78d956a1%2F9c80c17e2ad977f79cb9e3d34b3ab0f5d0368aaa-1400x1314.png?alt=media) | ![](https://4149080208-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgY6xtY9ZQd9XMpvWlGM0%2Fuploads%2Fgit-blob-6f241352dd19f13186e41fd9c0ad6f03d02395bb%2Ff8761eb598ae30bbba73fcee581ebcac7c18c186-1400x1314.png?alt=media) |

## Show a file comparison view controller

The [`PTDiffViewController`](https://sdk.apryse.com/api/ios/Classes/PTDiffViewController.html) class shows a control to select two documents and create a new file showing the visual difference between them with customizable colors.

![](https://4149080208-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgY6xtY9ZQd9XMpvWlGM0%2Fuploads%2Fgit-blob-2727db11cebe81b27da1067349242ce355ea58cf%2Ffaee6f763f2c48ed2ea67aa5a9c43a3d6fe9a5b4-750x1624.png?alt=media)

*The file comparison control is part of the Tools library, so make sure you have* [*added the Tools library to your project*](/ios/ui-customization/setup.md)*.*

{% tabs %}
{% tab title="Swift" %}
{% code lineNumbers="true" %}

```swift
// Initialize a file comparison view controller.
let diffViewController = PTDiffViewController()

// Set the current view controller as the annotation view controller's delegate.
diffViewController.delegate = self

let navigationController = UINavigationController(rootViewController: diffViewController)
if ( UIDevice.current.userInterfaceIdiom == .pad ) {
    navigationController.modalPresentationStyle = .popover
    navigationController.popoverPresentationController?.barButtonItem = documentComparisonButton
}

self.present(navigationController, animated: true, completion: nil)
```

{% endcode %}
{% endtab %}

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

```objc
// Initialize a file comparison view controller.
PTDiffViewController *diffViewController = [[PTDiffViewController alloc] init];

// Set the current view controller as the annotation view controller's delegate.
diffViewController.delegate = self;

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:diffViewController];
if ( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad ) {
    navigationController.modalPresentationStyle = UIModalPresentationPopover;
    navigationController.popoverPresentationController.barButtonItem = self.documentComparisonButton;
}

[self presentViewController:navigationController animated:YES completion:nil];
```

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

{% hint style="warning" %}
**The diff view controller must be pushed onto a navigation controller's stack before being shown.**
{% endhint %}

{% hint style="info" %}
**Retrieving the file comparison output.**

The `PTDiffViewController` creates an output file showing the visual difference between the two documents in a temporary directory and returns an [`NSURL`](https://developer.apple.com/foundation/nsurl/) with the file's location via a delegate method. To save and display the file, you must conform to the `PTDiffViewControllerDelegate` protocol.
{% endhint %}

## File comparison sample code

The following sample code demonstrates how to use `PDFNet` to generate a document displaying the visual difference between two PDF pages:

{% tabs %}
{% tab title="Swift" %}
{% code lineNumbers="true" %}

```swift
func pdfCompareDoc(docA: PTPDFDoc, docB: PTPDFDoc, colorA: PTColorPt, colorB: PTColorPt, blendMode: PTBlendMode) -> PTPDFDoc {
    let pageA = docA.getPage(1)
    let pageB = docB.getPage(1)

    let diffOptions:PTDiffOptions = PTDiffOptions()
    diffOptions.setColorA(colorA)
    diffOptions.setColorB(colorB)
    diffOptions.setBlendMode(blendMode)

    let doc:PTPDFDoc = PTPDFDoc()
    doc.appendVisualDiff(pageA, p2: pageB, opts: diffOptions)
    return doc
}
```

{% endcode %}
{% endtab %}

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

```objc
- (PTPDFDoc*)pdfCompareDoc:(PTPDFDoc*)docA withDoc:(PTPDFDoc*)docB colorA:(PTColorPt*)colorA colorB:(PTColorPt*)colorB blendMode:(PTBlendMode)blendMode
{
    PTPage *pageA = [docA GetPage:1];
    PTPage *pageB = [docB GetPage:1];

    PTDiffOptions *diffOptions = [[PTDiffOptions alloc] init];
    [diffOptions SetColorA:colorA];
    [diffOptions SetColorB:colorB];
    [diffOptions SetBlendMode:blendMode];

    PTPDFDoc *doc = [[PTPDFDoc alloc] init];
    [doc AppendVisualDiff:pageA p2:pageB opts:diffOptions];
    return doc;
}
```

{% 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/ios/compare-files/file-comparison-i.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.
