Open a document

You have a few options to open a document such as with a document view controller, tabbed document view controller or an embedded view.

Document view controller

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

Apryse Docs Image

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 is a subclass of the PTDocumentBaseViewController 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.

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

1// Create a PTDocumentController
2let documentController = PTDocumentController()
3
4// The PTDocumentController must be in a navigation controller before a document can be opened
5let navigationController = UINavigationController(rootViewController: documentController)
6
7// Open an existing local file URL.
8let fileURL: URL! = Bundle.main.url(forResource: "sample", withExtension: "pdf")
9
10documentController.openDocument(with: fileURL)
11
12// Show navigation (and document) controller.
13self.present(navigationController, animated: true, completion: nil)

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.

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales