Display PDF using PDFViewCTRL on iOS

Displaying a PDF

The easiest way to display a PDF is using a PTDocumentController. The PTPDFViewCtrl is a low-level control that may be used when a higher level of customization is required.

About PTPDFViewCtrl

The PTPDFViewCtrl is a UIView that displays a PDF.

If your app is displaying a PDF, a PTPDFViewCtrl will be used in one of two ways:

  • Directly, by adding it as a subview to another view in your app.
  • As a component piece of a PTDocumentController or PTTabbedDocumentViewController. (It is accessible via the pdfViewCtrl property.)

Use PTPDFViewCtrl as a stand-alone component

  1. These instructions assume that you've initialized Apryse.
  2. Add a PDF to your project, by dragging it into the project's left side panel. Ensure that it will be copied into the bundle's resources by checking that it is listed under the Copy Bundle Resources section of the project's Build Phases. (If it is not present here, add it using the '+' button.)The file sample.pdf has been added to the project, and will be copied into the bundle.
Apryse Docs Image
  1. Instantiate a new PTPDFDoc:
1// Get the path to document in the app bundle.
2NSString* pdfPath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"pdf"];
3
4// Instantiate a new PDFDoc with the path to the file.
5PTPDFDoc* docToOpen = [[PTPDFDoc alloc] initWithFilepath:pdfPath];
  1. Create a new PTPDFViewCtrl and add it as a child to the current view:Running the app will now display the PDF sample.pdf. However, it will not support annotation creation, editing, text selection, or any other UI aspect that is handled by Tools.framework . To add support for annotations and text selection you need to incorporate the tools framework .
1// Create a new PDFViewCtrl
2PTPDFViewCtrl* pdfViewCtrl = [[PTPDFViewCtrl alloc] init];
3
4// Set the document to display
5[pdfViewCtrl SetDoc:docToOpen];
6
7// Add the PDFViewCtrl to the current view controller's root view.
8[self.view addSubview:pdfViewCtrl];
9
10// Set the size of the PDFViewCtrl to that of its superview.
11// (Auto Layout is fully supported as well)
12pdfViewCtrl.frame = self.view.bounds;
13pdfViewCtrl.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales