> 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 transform PDF form fields

> Learn how to use PDF form field transformation within the Apex Toolkit.

This topic demonstrates how to use [PDF form field transformation](/docs/esign-rest-api/esign101/concepts/tabs/pdf-transform) within the Apex Toolkit to convert PDF form fields in your Salesforce library documents to Docusign [tabs](/docs/esign-rest-api/esign101/concepts/tabs) automatically.

## Prerequisites

1. Install the [Docusign eSignature for Salesforce](/docs/salesforce/how-to/apex-toolkit-install)  managed package.
2. Create a subdomain for your Salesforce organization by enabling "My Domain."
3. Select the **Docusign Setup** tab and complete the login step.
4. Upload a PDF containing form fields to a Salesforce library by going to **App Launcher** > **Sales Console** > **Files** and selecting **Upload Files**.

## Required data

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

| Data element           | Description                                                                                                                                       |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| Contact ID             | The ID of the Salesforce Contact that will receive the envelope.                                                                                  |
| Content Document ID    | The ID of a document stored in a Salesforce library.                                                                                              |
| Documents to be signed | You must provide at least one document to be signed. To use PDF form field transformation, your document needs to be a PDF file with form fields. |
| Source ID              | The ID of the Salesforce Contact from whom the Docusign envelopes will be sent.                                                                   |

## Step 1. Define your public class and method

Create one public class and one public method that will contain the code for this how-to. You can skip this step if you are adding this code to an existing class.

**`Apex`**

```java title="Apex"
public class TransformPDF {
    public static void sendEnvelope() {
    }
}
```

## Step 2. Create an empty envelope and recipient

Use the [dfsle.EnvelopeService.getEmptyEnvelope](/docs/salesforce/apex-toolkit-reference/envelopeservice.html) method to create a new envelope. Specify the Salesforce Contact ID of the record in the `Entity` parameter that is to be used as the sender of the envelope. Create a `Recipient` object for each recipient of the envelope. These recipient objects contain the full set of data on the recipient's role in the signing process: their role, authentication data, status in the workflow, and contact settings. In this how-to, the envelope will have one recipient: a document signer. Once a recipient is created, use the [withRecipients](/docs/salesforce/apex-toolkit-reference/envelope.html) method to add it to the envelope.

The accompanying code demonstrates the workflow for adding recipient data to the envelope.

**`Apex`**

```java title="Apex"
Id mySourceId = '0034xxxxxxxxxx4QAE'; // The Salesforce Contact ID of the sender
// Create an empty envelope.
dfsle.Envelope myEnvelope = dfsle.EnvelopeService.getEmptyEnvelope(
new dfsle.Entity(mySourceId));

// We will use a Salesforce Contact ID as a Recipient here
Contact myContact = [SELECT Id, Name, Email FROM Contact WHERE Id = '0034xxxxxxxxxxcQAG'];
// Use the Recipient.fromSource method to create the Recipient
dfsle.Recipient myRecipient = dfsle.Recipient.fromSource(
    myContact.Name, // Recipient name
    myContact.Email, // Recipient email
    null, //Optional phone number
    'Signer 1', //Role Name. Specify the exact role name from template
    new dfsle.Entity(myContact.Id));
// Add Recipient to the Envelope
myEnvelope = myEnvelope.withRecipients(new List<dfsle.Recipient> { myRecipient });
```

## Step 3. Get a document with PDF options enabled

Create a new [dfsle.Document](/docs/salesforce/apex-toolkit-reference/document.html) using the [dfsle.DocumentService.getDocuments](/docs/salesforce/apex-toolkit-reference/documentservice.html) method. In this how-to, you will use a PDF file containing form fields that you’ve uploaded to a Salesforce library. To get the Content Version ID of that document, write a query using Salesforce Object Query Language (SOQL) to find Content Versions associated with the Content Document ID. Passing that Content Version ID to the `getDocuments` method will return a list of `dfsle.Document` objects. Index the returned list to get the first document and use the `.withPdfOptions` method to enable PDF form field transformation. Then add the document to your envelope.

The accompanying code demonstrates how to get your document from Salesforce and add it to the envelope.

**`Apex`**

```java title="Apex"
Id myFileId = [SELECT id from ContentVersion where ContentDocumentId = '0694xxxxxxxxxxyQAD' LIMIT 1].id; // Content version ID of document to send
dfsle.Document myDocument = dfsle.DocumentService.getDocuments(ContentVersion.getSObjectType(), new Set<Id> { myFileId }).get(0);
myDocument.withPdfOptions(new dfsle.Document.PdfOptions(
    true, // Whether to transform PDF form fields
    1)); // The recipient for which to apply the tags

//Add document to the Envelope
myEnvelope = myEnvelope.withDocuments(new List<dfsle.Document> { myDocument });
```

## Step 4. Send the envelope

Send the envelope using the [dfsle.EnvelopeService.sendEnvelope](/docs/salesforce/apex-toolkit-reference/envelopeservice.html) method. The `sendNow` parameter is set to `true` to indicate that you want to send the envelope immediately. Setting the `sendNow` parameter to `false` will save the envelope as a draft so it can be sent later.

The accompanying code demonstrates how to send the envelope.

**`Apex`**

```java title="Apex"
// Send the envelope
myEnvelope = dfsle.EnvelopeService.sendEnvelope(
    myEnvelope,
    true);
```

## Step 5. Execute your method

To execute your code, go to the [Developer Console](https://help.salesforce.com/s/articleView?language=en_US\&id=sf.code_dev_console.htm\&type=5) in Salesforce, open the **Debug** menu, then select **Open Execute Anonymous Window**. Type the accompanying code in the window and select **Execute**.

If you skipped step 1 and added your code to an existing class or method, you'll need to replace the class and method names with your own.

> **Note**
>
> View the source code for this how-to on GitHub: [Apex](https://github.com/docusign/code-examples-apex/blob/master/force-app/main/default/classes/TransformPDF.cls)

**`Apex`**

```java title="Apex"
PdfTransform.sendEnvelopeMethod();
```

## Expected response

If your API call is successful, the recipient should receive an email notification asking them to sign the documents in the envelope. All form fields from your PDF will be transformed to Docusign [tabs](/docs/esign-rest-api/reference/envelopes/enveloperecipienttabs).

## Next steps

* See all available Apex Toolkit [How-to guides](/docs/salesforce/how-to).
* Learn more about [PDF form field transformation](/docs/esign-rest-api/esign101/concepts/tabs/pdf-transform).
* See [How to perform unit testing](/docs/salesforce/how-to/unit-testing) to ensure that you have adequate code coverage.