Using Forms Service API in AEM Forms to render interactive PDF
In this article we will take a look at the following service
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();
renderOptions.setAcrobatVersion(AcrobatVersion.Acrobat_11);
renderOptions.setContentRoot(uri);
Document interactivePDF = null;
try {
interactivePDF = formsService.renderPDFForm("schengen.xdp", xmlData, renderOptions);
} catch (FormsServiceException e) {
e.printStackTrace();
}
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
Download and install the DocumentServices Sample Bundle using the Felix Web Console
Download and install the package using the AEM package manager
Search for Adobe Granite CSRF Filter
Add the following path in the excluded sections and save
/bin/generateinteractivepdf
Search for Apache Sling Service User Mapper Service and click to open the properties
Fill in a couple of fields and then click the Download and fill … button
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