Build a full-featured PDF reader (UI Extensions)
This guide shows how to use the UI Extensions component to build a full-featured PDF reader with a built-in toolbar and common feature modules.
INFO
For display-only PDF viewing without built-in UI, see Build a basic PDF reader (PDFViewCtrl).
Prerequisites
- Complete Integrate Foxit PDF SDK (project setup, SDK integration, license initialization).
- Add
uiextensionsDynamic.framework(see Enable UI Extensions).
Step 1: Add UI Extensions and build the full reader
Core steps:
- Create
FSPDFViewCtrlas the rendering and interaction container. - Create
UIExtensionsManagerand bind it toFSPDFViewCtrl. - Open a document with
FSPDFViewCtrl.openDoc.
Objective-C
objc
#import <FoxitRDK/FSPDFViewControl.h>
#import <FoxitRDK/FSPDFObjC.h>
#import <uiextensionsDynamic/UIExtensionsManager.h>
@interface ViewController () <IDocEventListener>
@property (nonatomic, strong) FSPDFViewCtrl *pdfViewCtrl;
@property (nonatomic, strong) UIExtensionsManager *extensionsMgr;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Initialize FSPDFViewCtrl
self.pdfViewCtrl = [[FSPDFViewCtrl alloc] initWithFrame:self.view.bounds];
[self.view addSubview:self.pdfViewCtrl];
// Initialize UIExtensionsManager with JSON config (optional)
NSString *configPath = [[NSBundle mainBundle] pathForResource:@"uiextensions_config" ofType:@"json"];
NSData *configData = [NSData dataWithContentsOfFile:configPath];
self.extensionsMgr = [[UIExtensionsManager alloc] initWithPDFViewControl:self.pdfViewCtrl
configuration:configData];
self.pdfViewCtrl.extensionsManager = self.extensionsMgr;
// Register document event listener
[self.pdfViewCtrl registerDocEventListener:self];
// Open PDF
NSString *path = [[NSBundle mainBundle] pathForResource:@"Sample" ofType:@"pdf"];
[self.pdfViewCtrl openDoc:path password:nil completion:^(FSErrorCode error) {
if (error != FSErrSuccess) {
NSLog(@"打开文档失败,错误码: %d", (int)error);
}
}];
}
@endSwift
swift
import FoxitRDK
import uiextensionsDynamic
class ViewController: UIViewController, IDocEventListener {
var pdfViewCtrl: FSPDFViewCtrl!
var extensionsMgr: UIExtensionsManager!
override func viewDidLoad() {
super.viewDidLoad()
// Initialize FSPDFViewCtrl
pdfViewCtrl = FSPDFViewCtrl(frame: view.bounds)
view.addSubview(pdfViewCtrl)
// Initialize UIExtensionsManager with JSON config (optional)
let configPath = Bundle.main.path(forResource: "uiextensions_config", ofType: "json")
let configData = configPath.flatMap { try? Data(contentsOf: URL(fileURLWithPath: $0)) }
extensionsMgr = UIExtensionsManager(pdfViewControl: pdfViewCtrl, configuration: configData)
pdfViewCtrl.extensionsManager = extensionsMgr
// Register document event listener
pdfViewCtrl.register(self as IDocEventListener)
// Open PDF
if let path = Bundle.main.path(forResource: "Sample", ofType: "pdf") {
pdfViewCtrl.openDoc(path, password: nil) { error in
if error != .errSuccess {
print("打开文档失败,错误码: \(error.rawValue)")
}
}
}
}
}Note
UIExtensionsManager supports two initializers:
initWithPDFViewControl:— default configuration.initWithPDFViewControl:configuration:— customize enabled modules and UI via JSON.
See Customize UI with configuration for JSON details.
Step 2: Configure RMS support (optional)
To open RMS-protected documents, set Microsoft Azure app registration details:
objc
[self.pdfViewCtrl setRMSAppClientId:@"YOUR_CLIENT_ID" redirectURI:@"YOUR_REDIRECT_URI"];For iOS 13+ multi-window (Scenes) apps, forward MSAL callbacks in SceneDelegate:
objc
- (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts {
UIOpenURLContext *context = URLContexts.anyObject;
[FSPDFViewCtrl handleMSALResponse:context.URL sourceApplication:context.options.sourceApplication];
}Step 3: Run and verify
- Add a test file (for example
Sample.pdf) to the Xcode target’s Bundle Resources. - Select a simulator or device and choose Product → Run.
On success, the app shows a full PDF reader with annotations, search, bookmarks, forms, and other built-in features.