Some test text!
You have a few options to open a document such as with a document view controller, tabbed document view controller or an embedded view.
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
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.
// Create a PTDocumentViewController let documentController = PTDocumentViewController() // The PTDocumentViewController 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)
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
delegate property and implement the following optional methods:
documentViewControllerDidOpenDocument:to respond to successfully opening a document.
documentViewController:didFailToOpenDocumentWithError:to respond to an error during document opening.
documentViewController:destinationURLForDocumentAtURL:to control where remote or converted documents are saved.
Get the answers you need: Support
Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.
Select a platform to get started with your free trial.
Unlimited usage. No email address required.
PDFTron Receives USD$71 Million Growth Investment Led By Silversmith Capital PartnersLearn more