View a document using PTDocumentController
Open your ViewController file. This is either the
ViewController.swiftorViewController.mfile in the left pane depending on your choice of language. Import PDFNet and Tools libraries.
import PDFNet
import Tools#import <PDFNet/PDFNet.h>
#import <Tools/Tools.h>Override the
viewDidAppear()method in theViewControllerclass and then open the DocumentViewController using:
override func viewDidAppear(_ animated: Bool) {
// 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)
navigationController.modalPresentationStyle = .fullScreen
navigationController.navigationBar.isTranslucent = false
navigationController.toolbar.isTranslucent = false
// Open a file from URL.
let fileURL: URL = URL(string:"https://pdftron.s3.amazonaws.com/downloads/pl/sample.pdf")!
documentController.openDocument(with: fileURL)
// Show navigation (and document) controller.
self.present(navigationController, animated: true, completion: nil)
}- (void)viewDidAppear:(BOOL)animated {
// 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];
navigationController.modalPresentationStyle = UIModalPresentationFullScreen;
navigationController.navigationBar.translucent = NO;
navigationController.toolbar.translucent = NO;
// Open a file from URL.
NSURL *fileURL = [[NSURL alloc] initWithString:@"https://pdftron.s3.amazonaws.com/downloads/pl/sample.pdf"];
[documentController openDocumentWithURL:fileURL];
// Show navigation (and document) controller.
[self presentViewController:navigationController animated:YES completion:nil];
}Click on the white play button on the top left of your window to launch the application in the Simulator.
Your app should look like this:

Next step
Last updated
Was this helpful?