Add an API for Cordova / Ionic

The following example hides text highlight and arrow annotation creation tool from the quick menu and annotation toolbar:

To use in ToolManagerBuilder:

To use in ToolManager:

Disable annotation editing

To disable annotation editing for certain annotation type(s), you can set it in a centralized place with either ToolManagerBuilder or ToolManager depending on the fit.

The following example disables editing of ellipse and rectangle annotations:

To use in ToolManagerBuilder:

To use in ToolManager:

Disable functionality

Functionality that is not directly tied to annotation creation or editing such as text selection, form filling, link following etc. can also be disabled. Each functionality is in the form of a Tool. Once a Tool is disabled, ToolManager will never switch to it. Instead, it will switch to the Pan tool. Pan tool cannot be disabled.

The following example disables form filling and link following:

To use in ToolManagerBuilder:

To use in ToolManager:

3. Update the native Objective-C header

The Objective-C header defines the interface for the native methods called by JavaScript. The file is found at src/ios/PDFTron.h.

Add the method signature:

Obj-C

1-(void)save:(CDVInvokedUrlCommand*)command;

4. Implement the new method in the Objective-C implementation file

The Objective-C implementation file is found at src/ios/PDFTron.m. This file is where the underlying native implementation is written.

Sometimes this is as simple as a single line of code. In this case it is calling save, which is asynchronous, and which we want to return a string (the file path).

Obj-C

1-(void)save:(CDVInvokedUrlCommand *)command
2{
3 [self.documentViewController saveDocument:e_ptincremental completionHandler:^(BOOL success) {
4 // this code is executed after the document has successfully saved
5 NSString* filePath = self.documentViewController.coordinatedDocument.fileURL.path;
6
7 if (!filePath )
8 {
9 filePath = [self.documentViewController.document GetFileName];
10 }
11
12 CDVPluginResult* pluginResult;
13
14 if( success )
15 {
16 // return that the save commend succeeded, along with the file path
17 pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:filePath];
18 }
19 else
20 {
21 // return that the save commanf failed, along with the file path for the attempted save
22 pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:filePath];
23 }
24
25 [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
26
27 }];
28
29}

### 5. Push the code and integrate the updated plugin

Push your changes back to your forked copy of the repo.

Next, from the command line, navigate to the root of your Cordova app project and remove the Apryse Cordova plugin as follows:

zsh/bash

1cordova plugin remove pdftron-cordova

Then integrate your forked copy of the repo with the changes, using the appropriate names for your Git(Hub) name/repo:

zsh/bash

1cordova plugin add https://github.com:MyGithubOrg/pdftron-cordova-fork.git

The new method is now ready to use.

Note that if you later on need to update any code in the plugin (for example to add another method, or to fix a bug), you will need to remove and re-add the Cordova plugin every time in order to make the changes visible to your app.

6. Access the new functionality

The app can now access the new API as follows:

JavaScript

1this.viewer.save(function (s) {
2 console.log(s);
3 fileUrl = "file://" + encodeURI(s);
4 console.log(fileUrl);
5}, function (e) {
6 console.log(e);
7});

6. All done!

If you're only developing for iOS, then you're all done!

If you're also deploying on Android, you'll need to repeat steps 3 and 4 for Android.

If you're developing for both iOS and Android, please consider submitting a PR, as upstreaming the change will simplify your developing and make the API available for other Apryse customers.

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales