How Do I Present a PSPDFTabbedViewController in Cordova?

Our Cordova library was designed to present a PDFViewController modally. If your use case requires you to present a PDFTabbedViewController, you can extend the library in your own fork, as shown below.

1. Update pspdfkit.js

Declare presentTabs in pspdfkit.js, like this:

this.presentTabs = function (path, callback) {
	cordova.exec(
		function (result) {
			if (callback) callback(result);
		},
		function (error) {
			if (callback) callback(error);
		},
		'PSPDFKitPlugin',
		'presentTabs',
		[path],
	);
};

2. Update PSPDFKitPlugin.m

Implement the newly declared API in Objective-C, like so:

- (void)presentTabs:(CDVInvokedUrlCommand *)command {
    NSArray *paths = [command argumentAtIndex:0];

    PSPDFTabbedViewController *tabbedViewController = [[PSPDFTabbedViewController alloc] init];
    NSMutableArray *documents = [NSMutableArray new];
    for (NSString *path in paths) {
        PSPDFDocument *document = [[PSPDFDocument alloc] initWithURL:[self fileURLWithPath:path]];
        if (document) {
            [documents addObject:document];
        }
    }
    tabbedViewController.documents = [documents copy];
    _navigationController = [[UINavigationController alloc] initWithRootViewController:tabbedViewController];

    if (!_navigationController.presentingViewController) {
        [self.viewController presentViewController:_navigationController animated:YES completion:^{

            [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK]
                                        callbackId:command.callbackId];
        }];
    } else {
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR]
                                    callbackId:command.callbackId];
    }
}

3. Usage

This is how the newly added API would look in your Cordova JavaScript code:

PSPDFKit.presentTabs([
	'pdf/PSPDFKit 8 QuickStart Guide.pdf',
	'pdf/Form_example.pdf',
]);
Overlayed Save Button

For more information, refer to our How to Expose Native iOS APIs to Cordova blog post.