The AEM Forms and Adobe Sign Integration: Creating a Dynamic Contract

Alastair Malkin
Mar 23 · 5 min read

It is always fun when you have the chance to look at something you know in theory or have touched upon in the past, and go deeper and create something real. This is what has happened to us recently as we looked at how best to showcase AEM Forms’ dynamic capabilities by integrating with Pega to create a contract that can be then sent to Adobe Sign.

We had the chance to build an integration between Pega and AEM to generate a PDF dynamically based upon a payload sent to AEM. AEM would contain multiple Templates, and the payload would determine which ones to use to create a single merged PDF. The merged PDF would then contain the data specified in the payload, as well as adding additional information like the logo, footer and page numbering. Finally, a Signature Block would be included in the merged PDF. Here’s how it all works.

Overview

Flow

  1. Pega sends the documents that need to be attached in the final merged PDF. This could be the AEM DAM or other storage location.
  2. Pega calls the CreateContract Servlet running on AEM with a payload in JSON format describing the contents of the merged PDF.
  3. The CreateContract Servlet retrieves the XDP Templates listed in the JSON payload.
  4. The Output Service will use the JSON payload details and the XDP file to merge the data, create a TOC, add a Watermark if required and include the documents sent in step 1 as attachments.
  5. Using the Assembly Service, the final merged PDF is created and stored, again this could in the AEM DAM or other storage location.
  6. A response is sent back to PEGA containing the path to the merged PDF.

Now that Pega has the created PDF, it can now send it to Adobe Sign for signing. This step could also be achieved from AEM, but in this case the client wanted to send it from Pega.

To do this, a webapp was created in Pega to manage the flow:

  1. The response from the first step is the path to the merged PDF.
  2. In Pega, a Contract Creation webapp sends the path to the merged PDF to Adobe Sign and the email address of the respondent.
  3. Adobe Sign creates an Agreement to send to the respondent and sends the contract to sign.
  4. Adobe Sign returns an AgreementId to Pega.
  5. A Webhook connection has been created in Adobe Sign pointing to a Webhook in Pega.
  6. Once the contract has been signed, the Webhook sends a message to Pega.
  7. Pega can now retrieve the signed document, to be signed in their own infrastructure.

Installation

To achieve this flow, I will focus on what was needed from Adobe. The Pega integration and setup is a separate installation. Also, AEM Forms running on 6.5 works best on Windows.

The Adobe solutions:

AEM Forms

Much of the installation and configuration is detailed in the Forms User Guide but to demonstrate this flow I will only highlight the main configuration required:

That will be sufficient to recreate this flow.

The XDP templates

The approach we took was to create an XDP Template and an XML to map to. To create the XDP file you will need the Form Designer, and a Windows machine to run this. The Designer install file can be obtained in the email containing the link to AEM jar.

Step 1: New Template creation

  1. Create a New Form
  2. Select a PDF of the Contract form
  3. On the Import Options Select “Create an Interactive Form With a Flowable layout”

Step 2: Creation of the Text fields

Here you go through the XDP document and place the text fields where you want the data to be merged from the JSON payload.

An example of the XDP document in the Designer.

The JSON payload

This was relatively complicated when it came to providing a level of flexibility to the customer. The example demonstrates the type of data sent to AEM.

Example of the JSON payload

AEM

With AEM Forms installed, you can now start the process of building the tools to create the merged PDF in AEM:

  1. Create a Servlet that Pega can use to send the payload of JSON to define the PDF
  2. Load the XDP Templates under “/content/dam/formsanddocuments”
  3. Load the XML files of the structure expected by the XDP Templates

XML Files

We used real XML files in AEM to make the process easier, but this could done dynamically in code.

CreateContract Servlet

The central component of the whole flow. Pega will call this endpoint and pass the JSON payload.

Basic flow of the Servlet

If the request payload specified a DOC type and then only DOC file would be created. This generation was done with Apache POI, and there is a OSGI wrapper available for this process.

To generate the PDF we created string of XML in the DDX format, expected by the Document Services. Here we can include details about the final document title, the Watermark details, TOC, the merged PDFs and the attachments.

In conclusion

This approach is entirely configurable and does provide a level of flexibility to to integrate with AEM Forms and Adobe Sign to create a powerful way to create dynamic PDFs. The next steps are to provide security to the connection with AEM and streamline the process, including creating Template versions and storage. The vision is to create a tool that is robust and flexible enough to manage multiple users, documents and templates for the foreseeable future.

Contributes

Prateek Tewari and Pawan Mittal

Adobe Tech Blog

News, updates, and thoughts related to Adobe, developers…

Alastair Malkin

Written by

Adobe Tech Blog

News, updates, and thoughts related to Adobe, developers, and technology.

More From Medium

More from Adobe Tech Blog

More from Adobe Tech Blog

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade