> 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/compare-files/overlay.md).

# Compare files with overlay

Compare files visually using overlays with Apryse SDK for Xamarin.Android. Learn how to integrate UI components for file comparison in your app. Find differences quickly and efficiently. The Apryse Xa

Apryse SDK allows you to compare files visually using overlays.

{% tabs %}
{% tab title="Android" %}

## Overlay PDFs to find differences in Xamarin.Android

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

You can visually compare pages. This resolution independent comparison allows you to quickly spot differences between pages.

There are two main ways to integrate the out-of-box UI components in your application:

1. [Standalone activity](#standalone-activity)
2. [Comparison options dialog](#comparison-options-dialog)

## Standalone activity

The [`DiffActivity`](https://sdk.apryse.com/api/xamarinandroid/tools/api/pdftron.PDF.Controls.DiffActivity.html) is a standalone component that handles from picking two files to generating the comparison result.

![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-e0acc50b089b60d7a62919105114359fe5e7bbca%2F7e258cf5d39bf775c65ebdd01bd29a526bc05e25-600x1200.gif?alt=media)

1. Define the activity

{% hint style="warning" %}
\*\* Storage Permission \*\*

Please follow the latest Android best practices and guidelines outlined [here](https://developer.android.com/training/permissions/usage-notes/)
{% endhint %}

{% code lineNumbers="true" %}

```xml
<activity android:name="com.pdftron.pdf.controls.DiffActivity" android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize" android:theme="@style/PDFTronAppTheme" android:windowSoftInputMode="adjustPan" />
```

{% endcode %}

1. Show the activity

{% code lineNumbers="true" %}

```csharp
DiffActivity.Open(this);
```

{% endcode %}

## Comparison options dialog

If you have your own viewer already and only want to show the comparison options in your application, the [`DiffOptionsDialogFragment`](https://sdk.apryse.com/api/xamarinandroid/tools/api/pdftron.PDF.Dialog.Diffing.DiffOptionsDialogFragment.html) can be used.

![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-dc20edcc3628942825e60d063a74ca64b7dbae9a%2F4bd7edf8d37e524b03207910636127cb026257fe-368x730.gif?alt=media)

{% code lineNumbers="true" %}

```csharp
public void Show(Context context, FragmentManager fragmentManager, List<Android.Net.Uri> files)
{
    var fragment = pdftron.PDF.Dialog.Diffing.DiffOptionsDialogFragment.NewInstance(
        files[0], files[1]
    );
    fragment.SetStyle((int)DialogFragmentStyle.Normal, Resource.Style.PDFTronAppTheme);
    fragment.DiffOptionsConfirmed += (sender, e) =>
    {
        CompareFiles(context, files, e.Color1, e.Color2, e.BlendMode);
    };
    fragment.Show(fragmentManager, "diff_options_dialog");
}
```

{% endcode %}

where `compareFile` is:

{% code lineNumbers="true" %}

```csharp
private void CompareFiles(Context context, List<Android.Net.Uri> files, int color1, int color2, int blendMode)
{
    Android.Net.Uri uri = pdftron.PDF.Dialog.Diffing.DiffUtils.CompareFilesImpl(context, files, color1, color2, blendMode);
    // do something with the output
}
```

{% endcode %}

`AsyncTask` pattern can be used instead of `Disposable` pattern if desired.
{% endtab %}

{% tab title="iOS" %}

## Overlay PDFs to find differences in Xamarin.iOS

{% 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)*.*

{% 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 %}

{% 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:

{% 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 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/xamarin/compare-files/overlay.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.
