> 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/document-viewer.md).

# Document view controller in Xamarin

Discover the PTDocumentController for PDF viewing and annotating with a range of controls like annotation toolbar, bookmarks, and more. Learn how to integrate this powerful tool into your project seam

The [`PTDocumentController`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTDocumentController.html) shows a PDF viewer and annotator complete with controls such as an annotation toolbar, page layout controls, bookmarks, thumbnail viewer, etc. All of its component pieces are part of the Tools framework, and this class packages them into one easy to use view controller.

For a version of `PTDocumentController` that supports multiple documents, see [`PTTabbedDocumentViewController`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTTabbedDocumentViewController.html).

![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-efcb719055c893f05756c361db34f29a7c9b6832%2F4b994036c8b8b340ce6e6886be3e57ab8d1166d3-1200x739.png?alt=media)

The document viewer includes a convenient document interaction and annotation toolbar at the top as well as convenient access to a number of powerful built-in components.

The [`PTDocumentController`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTDocumentController.html) is a subclass of the [`PTDocumentBaseViewController`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTDocumentBaseViewController.html) from which it inherits much of its functionality.

## Show a document

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

The following shows how to create a document viewer, set the document to display, and present it on screen.

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

```csharp
PTDocumentController documentController = new PTDocumentController();
UINavigationController navigationController = new UINavigationController(documentController);
NSUrl fileURL = NSBundle.MainBundle.GetUrlForResource("sample", "pdf");

documentController.OpenDocumentWithURL(fileURL);

documentController.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Done, (sender, e) => {
    documentController.DismissViewController(true, null);
});
this.PresentViewController(navigationController, true, null);
```

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

## Respond to Opening Events

`openDocumentWithURL:` is an asynchronous method. To respond to errors or other events that occur during opening, assign an object that conforms to the `PTDocumentControllerDelegate` to the `PTDocumentController`'s `delegate` property and implement the following optional methods:

* `documentControllerDidOpenDocument:` to respond to successfully opening a document.
* `documentController:didFailToOpenDocumentWithError:` to respond to an error during document opening.
* `documentController:destinationURLForDocumentAtURL:` to control where remote or converted documents are saved.


---

# 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/document-viewer.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.
