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:

1ToolManagerBuilder.from().disableToolMode(new ToolMode[]{
2 ToolManager.ToolMode.ARROW_CREATE,
3 ToolManager.ToolMode.TEXT_HIGHLIGHT}
4)

To use in ToolManager:

1mToolManager.disableToolMode(new ToolMode[]{
2 ToolManager.ToolMode.ARROW_CREATE,
3 ToolManager.ToolMode.TEXT_HIGHLIGHT}
4);

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:

1ToolManagerBuilder.from().disableAnnotEditing(new Integer[]{
2 Annot.e_Circle,
3 Annot.e_Square}
4);

To use in ToolManager:

1mToolManager.disableAnnotEditing(new Integer[]{
2 Annot.e_Circle,
3 Annot.e_Square}
4);

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:

1ToolManagerBuilder.from().disableToolMode(new ToolMode[]{
2 ToolManager.ToolMode.LINK_ACTION,
3 ToolManager.ToolMode.FORM_FILL}
4)

To use in ToolManager:

1mToolManager.disableToolMode(new ToolMode[]{
2 ToolManager.ToolMode.LINK_ACTION,
3 ToolManager.ToolMode.FORM_FILL}
4);

3. Define the method string that matches the JS declaration

Open file src/android/com/pdftron/cordova/PDFTron.java.

Add the method key that matches the JS declaration:

Java

1public static final String Key_save = "save";

4. Implement the new method

In the same file, src/android/com/pdftron/cordova/PDFTron.java, find entry point execute method:

Java

1@Override
2public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
3 if (Key_save.equals(action)) {
4 save(callbackContext);
5 }
6}
7
8private void save(CallbackContext callbackContext) {
9 cordova.getActivity().runOnUiThread(() -> {
10 if (mDocumentView != null) {
11 try {
12 if (mDocumentView.mPdfViewCtrlTabHostFragment != null && mDocumentView.mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment() != null) {
13 mDocumentView.mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment().save(false, true, true);
14 callbackContext.success(mDocumentView.mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment().getFilePath());
15 } else {
16 callbackContext.error("Saving failed.");
17 }
18 } catch (Exception ex) {
19 callbackContext.error(ex.getMessage());
20 }
21 }
22 });
23}

The actual implementation will depend on the actual functionality.

### 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 Android, then you're all done!

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

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