> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/android/get-started/get-started/cordova/add-an-api.md).

# Add an API for Cordova / Ionic

Learn how to integrate PDFTron's Cordova plugin for Android and iOS development. Follow step-by-step instructions to implement the method keys and execute the entry point method in your project. Simpl

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

To use in `ToolManagerBuilder`:

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
ToolManagerBuilder.From().DisableToolMode(new ToolManager.ToolMode[] {
    ToolManager.ToolMode.ArrowCreate,
    ToolManager.ToolMode.TextHighlight
});
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
ToolManagerBuilder.from().disableToolMode(new ToolMode[]{
    ToolManager.ToolMode.ARROW_CREATE,
    ToolManager.ToolMode.TEXT_HIGHLIGHT}
)
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
ToolManagerBuilder.from().disableToolMode(arrayOf(
    ToolManager.ToolMode.ARROW_CREATE,
    ToolManager.ToolMode.TEXT_HIGHLIGHT
))
```

{% endcode %}
{% endtab %}
{% endtabs %}

To use in `ToolManager`:

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
mToolManager.DisableToolMode(new ToolManager.ToolMode[] {
    ToolManager.ToolMode.ArrowCreate,
    ToolManager.ToolMode.TextHighlight
});
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
mToolManager.disableToolMode(new ToolMode[]{
    ToolManager.ToolMode.ARROW_CREATE,
    ToolManager.ToolMode.TEXT_HIGHLIGHT}
);
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
mToolManager.disableToolMode(arrayOf(
    ToolManager.ToolMode.ARROW_CREATE,
    ToolManager.ToolMode.TEXT_HIGHLIGHT
))
```

{% endcode %}
{% endtab %}
{% endtabs %}

## 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`:

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
ToolManagerBuilder.From().DisableAnnotEditing(new Java.Lang.Integer[]
{
    new Java.Lang.Integer((int)Annot.Type.e_Circle),
    new Java.Lang.Integer((int)Annot.Type.e_Square)
});
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
ToolManagerBuilder.from().disableAnnotEditing(new Integer[]{
    Annot.e_Circle,
    Annot.e_Square}
);
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
ToolManagerBuilder.from().disableAnnotEditing(arrayOf(Annot.e_Circle, Annot.e_Square))
```

{% endcode %}
{% endtab %}
{% endtabs %}

To use in `ToolManager`:

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
mToolManager.DisableAnnotEditing(new Java.Lang.Integer[]
{
    new Java.Lang.Integer((int)Annot.Type.e_Circle),
    new Java.Lang.Integer((int)Annot.Type.e_Square)
});
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
mToolManager.disableAnnotEditing(new Integer[]{
    Annot.e_Circle,
    Annot.e_Square}
);
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
mToolManager.disableAnnotEditing(arrayOf(Annot.e_Circle, Annot.e_Square))
```

{% endcode %}
{% endtab %}
{% endtabs %}

## 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`:

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
ToolManagerBuilder.From().DisableToolMode(new ToolManager.ToolMode[] {
    ToolManager.ToolMode.LinkAction,
    ToolManager.ToolMode.FormFill
});
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
ToolManagerBuilder.from().disableToolMode(new ToolMode[]{
    ToolManager.ToolMode.LINK_ACTION,
    ToolManager.ToolMode.FORM_FILL}
)
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
ToolManagerBuilder.from().disableToolMode(arrayOf(
    ToolManager.ToolMode.LINK_ACTION,
    ToolManager.ToolMode.FORM_FILL
))
```

{% endcode %}
{% endtab %}
{% endtabs %}

To use in `ToolManager`:

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
mToolManager.DisableToolMode(new ToolManager.ToolMode[] {
    ToolManager.ToolMode.LinkAction,
    ToolManager.ToolMode.FormFill
});
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
mToolManager.disableToolMode(new ToolMode[]{
    ToolManager.ToolMode.LINK_ACTION,
    ToolManager.ToolMode.FORM_FILL}
);
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
mToolManager.disableToolMode(arrayOf(
    ToolManager.ToolMode.LINK_ACTION,
    ToolManager.ToolMode.FORM_FILL
))
```

{% endcode %}
{% endtab %}
{% endtabs %}

### 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:

{% tabs %}
{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
public static final String Key_save = "save";
```

{% endcode %}
{% endtab %}
{% endtabs %}

### 4. Implement the new method

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

{% tabs %}
{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if (Key_save.equals(action)) {
        save(callbackContext);
    }
}

private void save(CallbackContext callbackContext) {
    cordova.getActivity().runOnUiThread(() -> {
        if (mDocumentView != null) {
            try {
                if (mDocumentView.mPdfViewCtrlTabHostFragment != null && mDocumentView.mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment() != null) {
                    mDocumentView.mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment().save(false, true, true);
                    callbackContext.success(mDocumentView.mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment().getFilePath());
                } else {
                    callbackContext.error("Saving failed.");
                }
            } catch (Exception ex) {
                callbackContext.error(ex.getMessage());
            }
        }
    });
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

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:

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
cordova plugin remove pdftron-cordova
```

{% endcode %}
{% endtab %}
{% endtabs %}

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

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

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

{% endcode %}
{% endtab %}
{% endtabs %}

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:

{% tabs %}
{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
this.viewer.save(function (s) {
    console.log(s);
    fileUrl = "file://" + encodeURI(s);
    console.log(fileUrl);
}, function (e) {
    console.log(e);
});
```

{% endcode %}
{% endtab %}
{% endtabs %}

### 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.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.apryse.com/android/get-started/get-started/cordova/add-an-api.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
