The AEM Forms and Adobe Sign Integration: Creating a Dynamic Contract
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.
- Pega sends the documents that need to be attached in the final merged PDF. This could be the AEM DAM or other storage location.
- Pega calls the CreateContract Servlet running on AEM with a payload in JSON format describing the contents of the merged PDF.
- The CreateContract Servlet retrieves the XDP Templates listed in the JSON payload.
- 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.
- Using the Assembly Service, the final merged PDF is created and stored, again this could in the AEM DAM or other storage location.
- 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:
- The response from the first step is the path to the merged PDF.
- In Pega, a Contract Creation webapp sends the path to the merged PDF to Adobe Sign and the email address of the respondent.
- Adobe Sign creates an Agreement to send to the respondent and sends the contract to sign.
- Adobe Sign returns an AgreementId to Pega.
- A Webhook connection has been created in Adobe Sign pointing to a Webhook in Pega.
- Once the contract has been signed, the Webhook sends a message to Pega.
- Pega can now retrieve the signed document, to be signed in their own infrastructure.
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 6.5
- AEM Forms Package
- Forms Designer (Windows only to create the XDP Templates/Fragments)
- Adobe Sign Developer Account
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:
- Install AEM Forms Package
- Add the Boot delegate RSA and BouncyCastle libraries as mentioned in Installing AEM Forms
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
- Create a New Form
- Select a PDF of the Contract form
- 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.
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.
With AEM Forms installed, you can now start the process of building the tools to create the merged PDF in AEM:
- Create a Servlet that Pega can use to send the payload of JSON to define the PDF
- Load the XDP Templates under “/content/dam/formsanddocuments”
- Load the XML files of the structure expected by the XDP Templates
We used real XML files in AEM to make the process easier, but this could done dynamically in code.
The central component of the whole flow. Pega will call this endpoint and pass the JSON payload.
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.
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.