> 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/ios/basic-operations/open/doc-view.md).

# Open using document view controller with Apryse iOS SDK

Learn how to open a document using a document view controller. The Apryse iOS SDK streamlines secure document processing and seamlessly integrates with major frameworks like Xamarin, React Native and

The [`PTDocumentController`](https://sdk.apryse.com/api/ios/Classes/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/ios/Classes/PTTabbedDocumentViewController.html).

![](https://4149080208-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgY6xtY9ZQd9XMpvWlGM0%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/ios/Classes/PTDocumentController.html) is a subclass of the [`PTDocumentBaseViewController`](https://sdk.apryse.com/api/ios/Classes/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*](/ios/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="Swift" %}
{% code lineNumbers="true" %}

```swift
// Create a PTDocumentController
let documentController = PTDocumentController()

// The PTDocumentController must be in a navigation controller before a document can be opened
let navigationController = UINavigationController(rootViewController: documentController)

// Open an existing local file URL.
let fileURL: URL! = Bundle.main.url(forResource: "sample", withExtension: "pdf")

documentController.openDocument(with: fileURL)

// Show navigation (and document) controller.
self.present(navigationController, animated: true, completion: nil)
```

{% endcode %}
{% endtab %}

{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

```objc
// Create a PTDocumentController
PTDocumentController *documentController = [[PTDocumentController alloc] init];

// The PTDocumentController must be in a navigation controller before a document can be opened
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:documentController];

// Open an existing local file URL.
NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"Sample" withExtension:@"pdf"];

[documentController openDocumentWithURL:fileURL];

// Show navigation (and document) controller.
[self presentViewController:navigationController animated:YES completion:nil];
```

{% 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/ios/basic-operations/open/doc-view.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.
