Foxit PDF SDK for iOS

How to Implement the UIExtensions project in Foxit PDF SDK for iOS

To customize the plugin UI, use the UIExtensions project. Foxit PDF SDK for iOS comes with a built-in UI design including the basic UI for app and the feature modules UI, which are implemented using Foxit PDF SDK and are shipped in the UI Extensions Component. Building a full-featured PDF Reader is getting simpler and easier. All you need to do is to instantiate a UIExtensionsManager object and set it to PDFViewCtrl.

Add code to instantiate a UIExtensionsManager object and set it to PDFViewCtrl

In the “ViewController.swift” file, you only need to add the following code:

import uiextensionsDynamic
...
var extensionsManager: UIExtensionsManager!
...
extensionsManager = UIExtensionsManager(pdfViewControl: pdfViewCtrl)
pdfViewCtrl.extensionsManager = extensionsManager;

Add permissions to access camera, microphone and photo library

To access the camera, microphone and photo library in iOS 9.0 or higher, you need to do the following configuration in the “Info.plist“.

NSCameraUsageDescription
 For adding photographs to your PDF files.

NSMicrophoneUsageDescription
 RDK need to add record permissions,please allow

NSPhotoLibraryAddUsageDescription
 RDK need to add picture permissions,please allow

NSPhotoLibraryUsageDescription
 For adding pictures to your PDF files.

The whole update of ViewController.swift is as follows:

import UIKit
import FoxitRDK
import uiextensionsDynamic

class ViewController: UIViewController {
    var extensionsManager: UIExtensionsManager!
    override func viewDidLoad() {
        super.viewDidLoad()

        // Get the path of a PDF.
        let pdfPath = Bundle.main.path(forResource: "Sample", ofType: "pdf")!

        // Initialize a FSPDFViewCtrl object with the size of the entire screen.
        var pdfViewCtrl: FSPDFViewCtrl!
        pdfViewCtrl = FSPDFViewCtrl.init(frame:self.view.bounds)

        // Set the document to display.
        pdfViewCtrl.openDoc(pdfPath, password: nil, completion: nil)

        // Add the pdfViewCtrl to the root view.
        self.view.insertSubview(pdfViewCtrl, at: 0)

        // Initialize a UIExtensionsManager object and set it to pdfViewCtrl.
        extensionsManager = UIExtensionsManager(pdfViewControl: pdfViewCtrl)
        pdfViewCtrl.extensionsManager = extensionsManager;

    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()

        // Dispose of any resources that can be recreated.
    }
}

Let’s run it on an iPhone 8 Simulator. Now, it is a full-featured PDF Reader as shown in Figure 3-15, which includes all of the features in Complete PDF Viewer demo. Feel free to try it.

Figure 3-15

Updated on July 21, 2021

Was this article helpful?
Thanks for your feedback. If you have a comment on how to improve the article, you can write it here: