> You are reading the Docusign Developer Documentation. For clean Markdown of any page, append .md to the page URL.
>
> Documentation indexes by section:
> - APIs and SDKs: https://docusign.docs.buildwithfern.com/docs/llms.txt
> - Platform 101: https://docusign.docs.buildwithfern.com/platform/llms.txt
> - Extension Apps: https://docusign.docs.buildwithfern.com/extension-apps/llms.txt
> - Docusign CLI: https://docusign.docs.buildwithfern.com/docusign-cli/llms.txt
>
> Authentication (OAuth, JWT Grant, M2M): https://docusign.docs.buildwithfern.com/platform/auth
> Webhooks and Connect: https://docusign.docs.buildwithfern.com/platform/webhooks
>
> OpenAPI specifications: https://docusign.docs.buildwithfern.com/openapi.json
> MCP server: https://docusign.docs.buildwithfern.com/_mcp/server

# How to create an envelope for offline signing (from a template)

> Learn how to create an envelope with the Android SDK from a template for offline signing.

This topic demonstrates how to create an [envelope](/docs/esign-rest-api/esign101/concepts/envelopes) from a [template](/docs/esign-rest-api/esign101/concepts/templates) for offline signing.

## Required data

Running the code in this how-to requires this data:

| Data element    | Description                                                                                                                                                                                                                                                                                              |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \{ROLE_NAME}    | A string value for the role name associated with the template recipient. This value can be defined upon template creation. This value must exactly match (case-sensitive) the value shown in the Role field assigned to the recipient in the template.                                                   |
| \{SIGNER_EMAIL} | A string value for the email address where the signer will receive a notification of the signing request.                                                                                                                                                                                                |
| \{SIGNER_NAME}  | A string value for the full name of the signer.                                                                                                                                                                                                                                                          |
| \{TAB_LABEL}    | A string value identifying a text-based tab to override in the template. This value can be defined upon template creation using the Data Label field. This value must exactly match (case-sensitive) the value shown in the tab’s Data Label field in the template.                                      |
| \{TAB_VALUE}    | A string value to assign to the text tab in the template.                                                                                                                                                                                                                                                |
| \{TEMPLATE_ID}  | A [GUID](http://guid.one/) value that identifies a Docusign [template](/docs/esign-rest-api/esign101/concepts/templates) that is used to create a Docusign [envelope](/docs/esign-rest-api/esign101/concepts/envelopes). This value is automatically generated by Docusign when the template is created. |

## Step 1. Log in to Docusign

To make the API call shown in this how-to, you must be logged in to Docusign.

See [How to log in to Docusign from your app](/docs/mobile-sdks/android-sdk/how-to/log-in) for details.

## Step 2. Cache template

Use the method shown to cache the template you wish to use to construct your envelope.

**`Java`**

```java title="Java"
DSTemplateDelegate templateDelegate = DocuSign.getInstance().getTemplateDelegate();
templateDelegate.cacheTemplate("{TEMPLATE_ID}", new DSCacheTemplateListener() {
    @Override
    public void onStart() {
        Log.d("cacheTemplate","cacheTemplate started");
    }

    @Override
    public void onComplete(DSTemplate template) {
        Log.d("cacheTemplate","cacheTemplate completed for template ID: " + template.getTemplateId());
}

    @Override
    public void onError(DSTemplateException exception) {
        Log.e("cacheTemplate", exception.getLocalizedMessage());
    }
});
```

**`Kotlin`**

```kotlin title="Kotlin"
val templateDelegate = DocuSign.getInstance().getTemplateDelegate()
templateDelegate.cacheTemplate(templateId, object : DSCacheTemplateListener {
    override fun onStart() {
        Log.d("cacheTemplate", "cacheTemplate started")
    }

    override fun onComplete(template: DSTemplate) {
        Log.d("cacheTemplate", "cacheTemplate complete")
    }

    override fun onError(exception: DSTemplateException) {
        Log.e("cacheTemplate", exception.localizedMessage)
    }
})
```

## Step 3. Create envelope defaults

When creating an envelope definition with a template, the documents, tabs, and most of the other envelope data will be automatically populated by your chosen template. To create an envelope from a template, you must:

* Specify the ID of the template.
* Specify the names, emails, and role names for each role in the template.
* Provide a custom string to be assigned as the value of any tab objects identified by \{TAB_LABEL} that you wish to override.

> **Note:** Only text-based tabs are supported for tab defaults.

**`Java`**

```java title="Java"
ArrayList<DSRecipientDefault> recipientDefaults = new ArrayList<DSRecipientDefault>();

String emailBlurb = "Please sign";
String envelopeTitle = "Investment Agreement";

DSRecipientDefault recipient1 = new DSRecipientDefault(
        "{SIGNER_NAME}",
        "{SIGNER_EMAIL}",
        1L, 	//RecipientID
        "{ROLE_NAME}",
        DSEnvelopeDefaultsUniqueRecipientSelectorType.ROLE_NAME
);

recipientDefaults.add(recipient1);

HashMap<String, String> tabValueDefaults = new HashMap<String, String>(){{
    put("{TAB_LABEL}","{TAB_VALUE}");
}};

DSEnvelopeDefaults envelopeDefaults = new DSEnvelopeDefaults(
        recipientDefaults,
        null,
        emailBlurb,
        envelopeTitle,
        tabValueDefaults,
        null
);
```

**`Kotlin`**

```kotlin title="Kotlin"
val recipientDefaults = ArrayList<DSRecipientDefault>()
val emailBlurb = "Please sign"
val envelopeTitle = "Investment Agreement"

// In person signer
val recipient1 = DSRecipientDefault(
    "{SIGNER_NAME}",
    "{SIGNER_EMAIL}",
    1L,
    "signer", DSEnvelopeDefaultsUniqueRecipientSelectorType.ROLE_NAME
)
recipientDefaults.add(recipient1)
val tabValueDefaults = hashMapOf<String, String>()

tabValueDefaults["{TAB_LABEL}"] = "{TAB_VALUE}"

val envelopeDefaults = DSEnvelopeDefaults(
    recipientDefaults,
    null,
    emailBlurb,
    envelopeTitle,
    tabValueDefaults,
    null
)
```

## Step 4. Create the envelope

Next, use the envelope defaults you created in the previous step to create an envelope.

**`Java`**

```java title="Java"
templateDelegate.useTemplateOffline(context,
    "{TEMPLATE_ID}",
    envelopeDefaults,
    new DSOfflineUseTemplateListener() {

        @Override
        public void onCancel(String templateId, String envelopeId) {
            Log.d("useTemplateOffline", "Signing canceled for envelope ID: " + envelopeId + " from template ID: " + templateId);
        }

        @Override
        public void onComplete(String envelopeId) {
            Log.d("useTemplateOffline", "Signing completed for envelope ID: " + envelopeId);
        }

        @Override
        public void onError(DSTemplateException exception) {
            Log.e("useTemplateOffline", exception.getLocalizedMessage());
        }
    }
);
```

**`Kotlin`**

```kotlin title="Kotlin"
templateDelegate.useTemplateOffline(
    applicationContext,
    "{TEMPLATE_ID}",
    envelopeDefaults,
    object : DSOfflineUseTemplateListener {
        override fun onCancel(templateId: String, envelopeId: String?) {
            Log.d(
                "useTemplateOffline",
                "Signing canceled for envelope ID: $envelopeId from template ID: $templateId"
            )
        }

        override fun onComplete(envelopeId: String) {
            Log.d(
                "useTemplateOffline",
                "Signing completed for envelope ID: $envelopeId"
            )
        }

        override fun onError(exception: DSTemplateException) {
            Log.e("useTemplateOffline", exception.localizedMessage)
        }
    }
)
```

## Expected response

If the account used for authentication is set as the signer for the envelope, you will see the Android SDK’s native offline signing screen, and be prompted to complete the offline signing process.

![Native signing screen, Android SDK](/_fern-files/_img/8cfaa578db1d5665786b70bba7f6c1753b6a8e80b216f1d50a9b91fb34dd19ee.webp)

Once signing has been completed, or if the envelope has a remote signer, the envelope will be cached directly for sync later.

## Next steps

* Learn [How to sync offline signed envelopes](/docs/mobile-sdks/android-sdk/how-to/sync-offline).
* See [How to create an envelope for offline signing (PDF)](/docs/mobile-sdks/android-sdk/how-to/offline-signing-pdf).
* See [Support Guide: How do I create a template?](https://support.docusign.com/s/articles/How-do-I-create-a-template)