How do I Present a PSPDFTabbedViewController in Cordova?

Q: How do I Present a PSPDFTabbedViewController in Cordova?

A: Our Cordova plugin was designed to present a PSPDFViewController modally. If your use case requires you to present a PSPDFTabbedViewController, you could extend the plugin in your own fork, as seen below.

1. Update pspdfkit.js

Declare presentTabs in pspdfkit.js, like this:

Copy
1
2
3
4
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:

Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
- (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:

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