> 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/xamarin/guides/viewer-components/file-comparison-i.md).

# Compare PDF files in Xamarin

Learn how to use the Apryse SDK for powerful file comparison in Xamarin.iOS. Create a file comparison view controller and retrieve the output with customizable colors. See sample code for generating v

{% hint style="info" %}
**This tutorial only applies to Xamarin.iOS. See Xamarin.Android equivalent here .**
{% endhint %}

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://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-a3fd7c34d0ff2a47e6601b447be105a324c06894%2Ffa37a99afc74d0f696f8e308cd3b454c8f31c321-1400x1314.png?alt=media) | ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-40d2ec0260cda7b9d3c91aa3c985c8ba78d956a1%2F9c80c17e2ad977f79cb9e3d34b3ab0f5d0368aaa-1400x1314.png?alt=media) | ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-6f241352dd19f13186e41fd9c0ad6f03d02395bb%2Ff8761eb598ae30bbba73fcee581ebcac7c18c186-1400x1314.png?alt=media) |

## Show a file comparison view controller

The [`PTDiffViewController`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.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://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%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*](/xamarin/ui-customization/setup.md)*.*

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
// Initialize a file comparison view controller.
var diffController = new PTDiffViewController();

diffController.DidCreateDiffFileAtURL += (sender, e) =>
{
    // Handle created diff file.
};

var navigationController = new UINavigationController(diffController);
if (!UserInterfaceIdiomIsPhone)
{
    navigationController.ModalPresentationStyle = UIModalPresentationStyle.Popover;

    navigationController.PopoverPresentationController.SourceView = btn;
    navigationController.PopoverPresentationController.SourceRect = btn.Bounds;
}

this.PresentViewController(navigationController, true, null);
```

{% 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="C#" %}
{% code lineNumbers="true" %}

```csharp
// Xamarin sample code coming soon
```

{% 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.apryse.com/xamarin/guides/viewer-components/file-comparison-i.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
