1

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.

2

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.

| improve this answer | |
  • Ok thanks for the heads-up on this! I ask one of our developers and he's currently investigating this point you're making. We'll get back to you after our investigation. Thanks! – Jerard Dela Victoria Jul 3 '19 at 6:48
  • Hi Renato, thanks for the help! Your sample and the links actually helped us in figuring out how to add the signature tag to our pdf. It's now working! Thanks. – Jerard Dela Victoria Jul 4 '19 at 2:09
  • @JerardDelaVictoria happy to know that this worked for you! :) – Renato Oliveira Jul 4 '19 at 2:37
  • thanks man! You really save us a lot of time with our investigation! Btw, if you don't mind... I have a follow-up question to this one. Maybe you also know the answer to this one considering your answer above about saving the attachment to Salesforce: salesforce.stackexchange.com/questions/268188/… – Jerard Dela Victoria Jul 4 '19 at 2:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.