Document view controller in Xamarin

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 for information.

The PTDocumentViewController 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.

Apryse Docs Image

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.

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

C#

1PTDocumentViewController documentController = new PTDocumentViewController();
2UINavigationController navigationController = new UINavigationController(documentController);
3NSUrl fileURL = NSBundle.MainBundle.GetUrlForResource("sample", "pdf");
4
5documentController.OpenDocumentWithURL(fileURL);
6
7documentController.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Done, (sender, e) => {
8 documentController.DismissViewController(true, null);
9});
10this.PresentViewController(navigationController, true, null);

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 PTDocumentViewControllerDelegate to the PTDocumentViewController's delegate property and implement the following optional methods:

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales