> 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-legacy.md).

# Document view controller in Xamarin

Learn how to use the legacy PTDocumentViewController class for PDF viewing and annotating. Upgrade to PTDocumentController for the latest features. Find out more in this comprehensive guide. The Aprys

{% hint style="info" %}
**Legacy Viewer**

This guide is for the legacy `PTDocumentViewController` class. This class is no longer being updated. For the best viewing experience and to take advantage of new developments, the `PTDocumentController` should be used. Please see [this guide](/ios/basic-operations/open/doc-view.md) for information.
{% endhint %}

The [`PTDocumentViewController`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTDocumentViewController.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 `PTDocumentViewController` 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 toolbar at the top and quick scroller at the bottom.

## Show a document

*The document view control 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
PTDocumentViewController documentController = new PTDocumentViewController();
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:`](https://sdk.apryse.com/api/ios/Classes/PTDocumentViewController.html#/c:objc\(cs\)PTDocumentViewController\(im\)openDocumentWithURL:) is an asynchronous method. To respond to errors or other events that occur during opening, assign an object that conforms to the [`PTDocumentViewControllerDelegate`](https://sdk.apryse.com/api/ios/Protocols/PTDocumentViewControllerDelegate.html) to the `PTDocumentViewController`'s [`delegate`](https://sdk.apryse.com/api/ios/Classes/PTDocumentViewController.html#/c:objc\(cs\)PTDocumentViewController\(py\)delegate) property and implement the following optional methods:

* [`documentViewControllerDidOpenDocument:`](https://sdk.apryse.com/api/ios/Protocols/PTDocumentViewControllerDelegate.html#/c:objc\(pl\)PTDocumentViewControllerDelegate\(im\)documentViewControllerDidOpenDocument:) to respond to successfully opening a document.
* [`documentViewController:didFailToOpenDocumentWithError:`](https://sdk.apryse.com/api/ios/Protocols/PTDocumentViewControllerDelegate.html#/c:objc\(pl\)PTDocumentViewControllerDelegate\(im\)documentViewController:didFailToOpenDocumentWithError:) to respond to an error during document opening.
* [`documentViewController:destinationURLForDocumentAtURL:`](https://sdk.apryse.com/api/ios/Protocols/PTDocumentViewControllerDelegate.html#/c:objc\(pl\)PTDocumentViewControllerDelegate\(im\)documentViewController: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-legacy.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.
