Rendering Interactive PDF using Forms Services in AEM Forms

Using Forms Service API in AEM Forms to render interactive PDF

In this article we will take a look at the following service

  • FormsService - This is a very versatile service which allows you to export/import data from and into PDF file and also generate interactive pdf by merging xml data into xdp template

The official javadoc for AEM Forms API is listed here

The following code snippet renders interactive pdf using the renderPDFForm operation of the FormsService. The schengen.xdp is template that is being used to merge the xml data.

String uri = "crx:///content/dam/formsanddocuments";
PDFFormRenderOptions renderOptions = new PDFFormRenderOptions();
Document interactivePDF = null;
try {
interactivePDF = formsService.renderPDFForm("schengen.xdp", xmlData, renderOptions);
} catch (FormsServiceException e) {
return interactivePDF;

Line 1: Location of the folder which contains the xdp template

Line2-4: Create PDFFormRenderOptions and set its properties

Line 7: Generate Interactive PDF using the renderPDFForm service operation of FormsService

Line 11: Returns the generated interactive pdf to the calling application

To test the sample package on your system

  1. Download and install the DocumentServices Sample Bundle using the Felix Web Console

  2. Download and install the package using the AEM package manager

  3. Login to configMgr

  4. Search for Adobe Granite CSRF Filter

  5. Add the following path in the excluded sections and save

  6. /bin/generateinteractivepdf

  7. Open the mobile form

  8. Fill in a couple of fields and then click the Download and fill … button

  9. The interactive pdf should be downloaded to your local system

The sample package contains the custom profile that is associated with the Mobile Form. Please explore the customtoolbar.jsp file. This jsp extracts the data from the mobile form and makes a POST request to servlet mounted on /bin/generateinteractivepdf path. The servlet return the interactive pdf to the calling application. The code in the customtoolbar.jsp then downloads the file to your local system

On this page