Some test text!

platform
search

PTPDFViewCtrl

Contents

About PTPDFViewCtrl
Using PTPDFViewCtrl as a Stand-Alone Component
Customize a PTPDFViewCtrl
Properties and Methods
Delegate Callbacks
Displaying a PDF
The easiest way to display a PDF is using a PTDocumentViewController. The PTPDFViewCtrl is a low-level control that may be used when a higher level of customization is required.

linkAbout 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 PTDocumentViewController or PTTabbedDocumentViewController. (It is accessible via the pdfViewCtrl property.)

linkUsing PTPDFViewCtrl as a Stand-Alone Component

  1. These instructions assume that you've initialized PDFTron.
  1. 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.
  1. Instantiate a new PTPDFDoc:

    // Get the path to document in the app bundle.
    let pdfPath: String? = Bundle.main.path(forResource: "sample", ofType: "pdf")
        
    // Instantiate a new PDFDoc with the path to the file.
    let docToOpen = PTPDFDoc(filepath: pdfPath)
  2. Create a new PTPDFViewCtrl and add it as a child to the current view:

    // Create a new PDFViewCtrl.
    let pdfViewCtrl = PTPDFViewCtrl()
    
    // Set the document to display.
    pdfViewCtrl.setDoc(docToOpen)
    
    // Add the PDFViewCtrl to the current view controller's root view.
    self.view.addSubview(pdfViewCtrl)
    
    // Set the size of the PDFViewCtrl to that of its superview.
    // (Auto Layout is fully supported as well)
    pdfViewCtrl.frame = self.view.bounds
    pdfViewCtrl.autoresizingMask = [.flexibleWidth, .flexibleHeight]

    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.

linkCustomize a PTPDFViewCtrl

The PDFViewCtrl has a large API that can be used to control how the PDF is presented to the user. All of the APIs that you can use are well documented. This guide highlights some of the most commonly used functionality.

If you are using a PTDocumentViewController (or PTTabbedDocumentViewController), the contained PTPDFViewCtrl can be accessed as a property:

let documentViewController = PTDocumentViewController()

documentViewController.pdfViewCtrl

linkProperties and Methods

APIDescription
SetPagePresentationModeSet how pages are presented and scrolled: in 1 or 2 columns, scrolled vertically or horizontally
SetPageViewModeSets the zoom level relative to the page size, fit-width, fit-height or fit-page.
SetPageRefViewModeWhen a document is scrolled via horizontal swipes, use this method to control what zoom level new pages are rendered at.
SetBackgroundColorSets the color that is seen around pages.
SetupThumbnailsControls how low-resolution thumbnails are handled. Enlarged thumbnails are used in place of high-resolution content while the high-resolution content is being rendered.
overlayViewThis view is used for drawing system-content over the PDF.
SetProgressiveRenderingControls how frequently the high-resolution content is updated while it is being rendered.
SetDrawAnnotationsControls if annotations are visible.
SetHighlightFieldsControls if form fields are shaded with light blue.
SetOverprintControls how PDFs that use overprint colors are rendered.
SetColorPostProcessModeCan be used to turn on night-mode and other color processing changes.

linkDelegate Callbacks

The PDFViewCtrl includes two delegates (delegate and toolDelegate) to relay touch and other events that occur on the control.

The first is a general purpose delegate, the second was designed specifically for enabling the Tools.framework functionality via its conforming object PTToolManager. If you are using the tools framework, a PTToolManager should always be assigned as the PTPDFViewCtrl's toolDelegate object. If you are not using the Tools.framework, it may be used for whatever purpose your app requires.

Delegates when using a PTDocumentViewController
When using a PTDocumentViewController (or PTTabbedDocumentViewController), the PTPDFViewCtrl delegates are used internally and cannot be reassigned to another object. To receive the delegate callbacks, create a subclass of PTDocumentViewController and implement the required methods, being sure to call super.

Get the anwsers you need: Support

Contents

About PTPDFViewCtrl
Using PTPDFViewCtrl as a Stand-Alone Component
Customize a PTPDFViewCtrl
Properties and Methods
Delegate Callbacks