[SalesForce] Is it possible to generate a PDF with a signature tag for DocuSign

Is it possible to generate a PDF using Apex and then embed the 'Signature tab' of DocuSign into the PDF?

For example: in the Contract Object we have a text area in which the user could add legal agreements, such as:

Agreements (Text Area):

I agree that this and that are true and correct…

Signature: signature_tag

We would like that when a user clicks on a custom button, called 'Send to Docusign', an Apex code is run that will convert the agreements text area above into a PDF, then it converts the tag into a 'Signature tab' that DocuSign interprets as the location where the client needs to sign.

Is this possible?

Thanks.

Best Answer

It looks like it is possible, although the steps are a little different than what you described.

From the DocuSign documentation, you can send the HTML body to their REST endpoint, and specify in the document body where you want the DocuSign tags to be.


Creating a Signable HTML Document

To pass in HTML to create a new HTML document in an envelope, use the following steps:

  1. In the JSON request body for a standard REST POST /accounts/{accountId}/envelopes method call, ensure that you have at least one document defined in the request’s documents block.

  2. For each HTML document in this section, add an htmlDefinition node.

  3. Within the htmlDefinition node, insert another node called source. Add your page’s HTML to the value of source. The following example shows an example documents node of a request to create a new signable HTML document.

"documents":[
   {  
      {
          "documentId": "1",
          "htmlDefinition":
           {
                "source": "<html><body><div>Example HTML page source</div></body></html>"
           }
      }
   }
 ]

There are two ways to specify the fields you want on the document:

  • You can add and configure the tabs directly by using specific inline HTML blocks. See Sending tabs as inline HTML for details.
  • You can embed JSON markers into the HTML that represent tabs. These markers will be replaced by tabs when the document is processed.

The signature tab type, for example, is <ds-signature/>. So if you can add that to the document that is passed to DocuSign's endpoint, then you'll be just fine. DocuSign will create the document for you, and then you can retrieve it on another call from Salesforce.

After the responsive HTML signing document has been created from the PDF, it is stored as an attachment tied to the envelope, which the calling system can retrieve.


So to summarize: your button would call an Apex code that calls a Visualforce page renderer, that will then get the body and pass to this endpoint. When the document is created by DocuSign you will need to make another call to retrieve the created document and, if necessary, save it as an attachment to the record on Salesforce.

Related Topic