> 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/basic-operations/basics/viewer/viewer-configuration.md).

# Customize a document view controller in Xamarin

Learn how to customize the PTDocumentController and PTTabbedDocumentViewController classes for your document viewer needs. Achieve modifications easily with this guide on APIs and UI framework. The Ap

{% hint style="info" %}
**This document refers to the PTDocumentController**

For the legacy `PTDocumentViewController` class, please see [this guide ](/xamarin/basic-operations/basics/viewer/viewer-configuration-legacy.md).
{% endhint %}

This article explains how to customize the document viewer classes [`PTDocumentController`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTDocumentController.html) and [`PTTabbedDocumentViewController`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTTabbedDocumentViewController.html).

Because the document viewer classes are part of the open source Tools UI framework, it is possible to achieve virtually any required modification. That said, it is usually faster and more convenient to configure the viewers via APIs, which this guide describes.

## PTDocumentController

{% tabs %}
{% tab title="Regular" %}
![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-f0923ebc5cc3ed865624052e94057f42968c41aa%2Ff68cb83052a7d9d84680780e384a7383227592c1-1024x665.png?alt=media)

The above image (items 1–5) indicates areas that are controllable via the `PTDocumentController`'s API. Information on customizing these is available [directly below](https://docs.apryse.com).

![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-441ef7cb126d5a63dfc3af2d2a6bd790154ed851%2F29fc6dcd8e42064fe759031d2c7f11c386ac718d-1024x200.png?alt=media)

The above image (items 7–12) indicates a number of default buttons that create and present new controls. Information on where to look to customize these presented controls can be found in the [component controls table](https://docs.apryse.com).
{% endtab %}

{% tab title="Compact" %}
![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-998e765d6f32707e13e7829baa79b67c5c6d1081%2Fe194a3ad168c7f597b0bf1b2394c94e5b3c512ee-1024x715.png?alt=media)

The **image on the left** (items 1–6) indicates areas that are controllable via the `PTDocumentController`'s API. Information on customizing these is available [directly below](https://docs.apryse.com).

The **image on the right** (items 7–12) indicates a number of default buttons that create and present new controls. Information on where to look to customize these presented controls can be found in the [component controls table](https://docs.apryse.com).
{% endtab %}
{% endtabs %}

On iPad and other regular horizontal size class devices, a number of default UI controls are accessible from the navigation bar, whereas on iPhones and compact size classes some of those controls appear in the toolbar at the bottom of the view.

| Image Number | Button                    | Functionality                                                                                                                      | Location on iPad                   | Location on iPhone                 |
| ------------ | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- | ---------------------------------- |
| 7            | searchButtonItem          | [`PTTextSearchViewController`](/xamarin/guides/ios/search/text-search.md#ui-component)                                             | navigationItem.rightBarButtonItems | navigationItem.rightBarButtonItems |
| 8            | moreItemsButtonItem       | [`PTMoreItemsViewController`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTMoreItemsViewController.html) | navigationItem.rightBarButtonItems | navigationItem.rightBarButtonItems |
| 10           | navigationListsButtonItem | [`PTNavigationListsViewController`](/xamarin/ui-customization/list-container.md#ios)                                               | navigationItem.leftBarButtonItems  | toolbar                            |
| 11           | thumbnailsButtonItem      | [`PTThumbnailsViewController`](/xamarin/page-manipulation/thumbnail-browser.md#ios)                                                | navigationItem.leftBarButtonItems  | toolbar                            |
| 12           | readerModeButtonItem      | [`PTReflowViewController`](/xamarin/guides/ios/viewer/view-mode.md#reflow)                                                         | navigationItem.rightBarButtonItems | toolbar                            |

### 1: Toolbar switcher

#### Hide the toolbar switcher

The toolbar switcher can be hidden:

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

```csharp
documentController.ToolGroupIndicatorView.Hidden = true;
```

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

#### Remove toolbars from the switcher

Toolbars can be removed by removing them from the toolGroupManager's groups array. The following code removes the "Draw" and "Pens" toolbars:

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

```csharp
var mutableGroups = documentController.ToolGroupManager.Groups;
var groupsToRemove = new List<PTToolGroup> { documentController.ToolGroupManager.DrawItemGroup, documentController.ToolGroupManager.PensItemGroup};
documentController.ToolGroupManager.Groups = mutableGroups.Except(groupsToRemove).ToArray();
```

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

### 2: Navigation bar items

The buttons which are contained in the [`leftBarButtonItems`](https://developer.apple.com/uikit/uinavigationitem/1624946-leftbarbuttonitems/) and [`rightBarButtonItems`](https://developer.apple.com/uikit/uinavigationitem/1624956-rightbarbuttonitems/) arrays, are completely customizable. It is possible to

* [Add buttons](https://docs.apryse.com)
* [Remove (hide) buttons](https://docs.apryse.com)
* [Move buttons](https://docs.apryse.com)
* [Change icons](https://docs.apryse.com)

#### Add buttons

You can modify the navigation bar items. Here is an example of adding a new button (for the current size class):

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

```csharp
var myItem = new UIBarButtonItem(UIImage.GetSystemImage("square.and.pencil"), UIBarButtonItemStyle.Plain, (sender, e) =>
{
    Console.WriteLine("button pressed:" + sender);
});

var currentItems = documentController.NavigationItem.RightBarButtonItems;
var itemsArray = new List<UIBarButtonItem>(currentItems);
itemsArray.Add(myItem);

documentController.NavigationItem.RightBarButtonItems = itemsArray.ToArray();
```

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

Tools can also be added:

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

```csharp
var freeHand = documentController.ToolGroupManager.CreateItemForToolClass(new ObjCRuntime.Class(typeof(PTFreeHandCreate)));

var currentItems = documentController.NavigationItem.RightBarButtonItems;
var itemsArray = new List<UIBarButtonItem>(currentItems);
itemsArray.Add(freeHand);

documentController.NavigationItem.RightBarButtonItems = itemsArray.ToArray();
```

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

Note that in the example above, de-selecting the tool button item needs to be implemented by the app, by listening to the Tool Did Change notification.

#### Remove buttons

To remove any of the default buttons see the instructions here: [Hide default buttons](https://developer.apple.com/uikit/uinavigationitem/1624946-leftbarbuttonitems/)

#### Move buttons

The default buttons are all accessible via properties, making it easy to rearrange or move them. The following code swaps the position of the search button and navigation lists button:

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

```csharp
var rightItems = documentViewController.NavigationItem.RightBarButtonItems;
var rightItemsList = new List<UIBarButtonItem>(rightItems);
rightItemsList.Remove(documentViewController.SearchButtonItem);
rightItemsList.Add(documentViewController.NavigationListsButtonItem);

var bottomRightItems = documentViewController.ThumbnailSliderController.TrailingToolbarItems;
var bottomRightItemsList = new List<UIBarButtonItem>(bottomRightItems);
bottomRightItemsList.Remove(documentViewController.NavigationListsButtonItem);
bottomRightItemsList.Add(documentViewController.SearchButtonItem);

documentViewController.NavigationItem.RightBarButtonItems = rightItemsList.ToArray();
documentViewController.ThumbnailSliderController.TrailingToolbarItems = bottomRightItemsList.ToArray();
```

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

#### Change icons

The icons of existing buttons may be changed by creating new `UIBarButtonItems` that have the same target and action as an existing item, and replacing the existing item with the new item:

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

```csharp
// new search UIBarButtonItem
var newSearchItem = new UIBarButtonItem(UIBarButtonSystemItem.Search, documentController.SearchButtonItem.Target, documentController.SearchButtonItem.Action);
index = rightItemsList.IndexOf(documentController.SearchButtonItem);
rightItemsList.Remove(documentController.SearchButtonItem);
rightItemsList.Insert(index, newSearchItem);

// update the icons
documentController.NavigationItem.RightBarButtonItems = rightItemsList.ToArray();
```

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

### 3: Annotation toolbar

The currently-visible annotation toolbar is selected with the [toolbar switcher](https://docs.apryse.com).

#### Hide (and show) the annotation toolbar

The toolbar can be programmatically hidden by setting the mode to view group, which is a special group and the only group where the toolbar is hidden:

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

```csharp
documentController.ToolGroupManager.SelectedGroup = documentController.ToolGroupManager.ViewItemGroup;
```

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

The toolbar can be shown again by changing the group to any group other than view:

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

```csharp
documentController.ToolGroupManager.SelectedGroup = documentController.ToolGroupManager.DrawItemGroup;
```

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

#### Remove buttons from a toolbar

The example below shows how to remove the text highlight and text underline button from a toolbar.

Disabling a tool type entirely

If you want to disable a tool entirely, from all toolbars and the long press menu, please use the [annotations permissions](/xamarin/guides/tools/customization.md#create-and-edit-annotations) system.

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

```csharp
var annotateGroup = documentController.ToolGroupManager.AnnotateItemGroup;

// tool buttons that exist currently
var defaultAnnotateGroupTools = annotateGroup.BarButtonItems;

// new set of tools to replace current ones
var newAnnotateGroupTools = new List<UIBarButtonItem>();

// add all currently existing tools except for the ones we don't want            
foreach (UIBarButtonItem defaultToolItem in defaultAnnotateGroupTools)
{
    if (defaultToolItem.IsKindOfClass(new ObjCRuntime.Class(typeof(PTToolBarButtonItem)))) {
        var toolBarButton = (PTToolBarButtonItem)defaultToolItem;
        if ( toolBarButton.ToolClass.Equals(new ObjCRuntime.Class(typeof(PTTextHighlightCreate))) ||
                toolBarButton.ToolClass.Equals(new ObjCRuntime.Class(typeof(PTTextUnderlineCreate))) )
        {
            // do not add this tool
            continue;
        }
        else
        {
            newAnnotateGroupTools.Add(toolBarButton);
        }
    }
    else
    {
        newAnnotateGroupTools.Add(defaultToolItem);
    }
}
// assign tools to new array
documentController.ToolGroupManager.AnnotateItemGroup.BarButtonItems = newAnnotateGroupTools.ToArray();
```

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

#### Add a tool button to a toolbar

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

```csharp
// create a mutable array of the current items in the annotation toolbar group
var availableTools = new List<UIBarButtonItem>(documentController.ToolGroupManager.AnnotateItemGroup.BarButtonItems);

// create a new toolbar item for freehand annotations
var freeHandItem = documentController.ToolGroupManager.CreateItemForToolClass(new ObjCRuntime.Class(typeof(PTFreeHandCreate)));

// add the freehand annotation item to the front of the list
availableTools.Insert(0, freeHandItem);

// assign the array back to the annotation toolbar group.
documentController.ToolGroupManager.AnnotateItemGroup.BarButtonItems = availableTools.ToArray();
```

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

### 4: Page number indicator

The page indicator can be enabled/disabled via the [`pageIndicatorEnabled`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTDocumentBaseViewController.html#pdftron_PDF_Controls_PTDocumentBaseViewController_PageIndicatorEnabled) property.

### 5: PDFViewCtrl

The `PTPDFViewCtrl` is a `UIView` that displays the PDF. It is customizable via is properties/methods and delegate methods.

For an overview see the [PTPDFViewCtrl Guide ](/xamarin/basic-operations/basics/viewer/pdfviewctrl.md#customize-a-ptpdfviewctrl), or the detailed [API documentation](https://sdk.apryse.com/api/xamarinandroid/pdfnet/api/pdftron.PDF.PDFViewCtrl.html).

Note that all PDF "interaction" (annotations, form filling, text selection, link following, etc.) is supplementary to the PDFViewCtrl, and is implemented in the open source [`tools.framework`](/xamarin/annotation/tools-overview.md#ios).

### 6. Toolbar (iPhone only)

These are the buttons that appear at the bottom of the screen on iPhones and in Compact horizontal size classes. Buttons can be added, removed, or rearranged with convenient APIs.

#### Add buttons to toolbar

#### Remove buttons from toolbar

To remove any of the default buttons see the instructions here: [Hide default buttons](https://docs.apryse.com)

### 7-12: Controls Presented by a PTDocumentController

To customize the controls that are presented by the `PTDocumentController`'s default buttons, please see the corresponding guide or API:

| Image number | Control                                                                                                                                    |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------ |
| 7            | [`PTTextSearchViewController`](/xamarin/guides/ios/search/text-search.md#ui-component)                                                     |
| 8            | [`PTMoreItemsViewController`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTMoreItemsViewController.html)         |
| 9            | [`PTPageIndicatorViewController`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTPageIndicatorViewController.html) |
| 10           | [`PTNavigationListsViewController`](/xamarin/ui-customization/list-container.md#ios)                                                       |
| 11           | [`PTThumbnailsViewController`](/xamarin/page-manipulation/thumbnail-browser.md#ios)                                                        |
| 12           | [`PTReflowViewController`](/xamarin/guides/ios/viewer/view-mode.md#reflow)                                                                 |

#### Hide default buttons

Default buttons can be removed ("hidden") using built-in properties.

* [`searchButtonHidden`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTDocumentBaseViewController.html#pdftron_PDF_Controls_PTDocumentBaseViewController_SearchButtonHidden)
* [`moreItemsButtonHidden`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTDocumentBaseViewController.html#pdftron_PDF_Controls_PTDocumentBaseViewController_moreItemsButtonHidden)
* [`navigationListsButtonHidden`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTDocumentBaseViewController.html#pdftron_PDF_Controls_PTDocumentBaseViewController_NavigationListsButtonHidden)
* [`thumbnailBrowserButtonHidden`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTDocumentBaseViewController.html#pdftron_PDF_Controls_PTDocumentBaseViewController_ThumbnailBrowserButtonHidden)
* [`readerModeButtonHidden`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTDocumentBaseViewController.html#pdftron_PDF_Controls_PTDocumentBaseViewController_ReaderModeButtonHidden)

For example to hide the search and more items buttons:

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

```csharp
documentController.SearchButtonHidden = true;
documentController.MoreItemsButtonHidden = true;
```

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

## PTTabbedDocumentViewController

The [tabbed document view controller](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTTabbedDocumentViewController.html) displays a collection of [document controllers](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTDocumentController.html) in tabs.

### Tab Settings

Tabs can be disabled using the [`TabsEnabled`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTTabbedDocumentViewController.html#pdftron_PDF_Controls_PTTabbedDocumentViewController_TabsEnabled) property, and the maximum number of allowed tabs can be set using [`MaximumTabCount`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTTabbedDocumentViewController.html#pdftron_PDF_Controls_PTTabbedDocumentViewController_MaximumTabCount).

### Access to child PTDocumentControllers

The current document controller can be accessed via [`SelectedViewController`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTTabbedDocumentViewController.html), and others via [`documentViewControllerAtIndex`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTTabbedDocumentViewController.html)

To configure a document controller before it is displayed, conform to and implement the [`PTTabbedDocumentViewControllerDelegate`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTTabbedDocumentViewControllerDelegate.html) method [`willAddDocumentViewController`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTTabbedDocumentViewControllerDelegate.html). Note that it **is** permissible to assign the internal `PTDocumentViewController`'s delegate to an external object.

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

```csharp
tabbedDocumentViewController.WillAddDocumentViewController += (sender, e) =>
{
    // do something with e.DocumentViewController
};
```

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

### Summary

| API                                                                                                                                                                                               | Functionality                                                         |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
| [`TabsEnabled`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTTabbedDocumentViewController.html#pdftron_PDF_Controls_PTTabbedDocumentViewController_TabsEnabled)         | Enables/disables tabs.                                                |
| [`MaximumTabCount`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTTabbedDocumentViewController.html#pdftron_PDF_Controls_PTTabbedDocumentViewController_MaximumTabCount) | Controls the maximum number of concurrent tabs.                       |
| [`SelectedViewController`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTTabbedDocumentViewController.html)                                                              | The current `PTDocumentViewController`.                               |
| [`documentViewControllerAtIndex`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTTabbedDocumentViewController.html)                                                       | The `PTDocumentViewController` at the given index.                    |
| [`willAddDocumentViewController`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTTabbedDocumentViewControllerDelegate.html)                                               | Access to a `PTDocumentViewController` that is about to be displayed. |


---

# 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/basic-operations/basics/viewer/viewer-configuration.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.
