Using Output and Forms Service API in AEM Forms
In this article we will take a look at the following
The following code snippet exports data from PDF file
javax.servlet.http.Part pdfPart = request.getPart("pdffile");
String filePath = request.getParameter("saveLocation");
java.io.InputStream pdfIS = pdfPart.getInputStream();
com.adobe.aemfd.docmanager.Document pdfDocument = new com.adobe.aemfd.docmanager.Document(pdfIS);
com.adobe.fd.forms.api.FormsService formsservice = sling.getService(com.adobe.fd.forms.api.FormsService.class);
com.adobe.aemfd.docmanager.Document xmlDocument = formsservice.exportData(pdfDocument,com.adobe.fd.forms.api.DataFormat.Auto);
Line 1 extracts pdffile from the request
Line2 extracts the saveLocation from the request
Line 5 gets hold of FormsService
Line 6 exports the xmlData from the PDF File
To test the sample package on your system
Download and install the package using the AEM package manager
After you install the package you will have to allowlist the following URLs in Adobe Granite CSRF Filter.
Make sure you have selected “POST” from the drop down list
http://localhost:4502/content/AemFormsSamples/exportdata.html
Make sure you specify “Authorization” as “Basic Auth”. Specify the AEM Server username and password
Navigate to the “Body” tab and specify the request parameters as shown in the image below
Then click the Send button
The package contains 3 samples. The following paragraphs explain when to use the output service or Forms Service, the url of the service ,input parameters that each service expects
Use Output Service to merge data with xdp or pdf document to generate flattened pdf
POST URL: http://localhost:4502/content/AemFormsSamples/outputservice.html
Request Parameters -
Use FormsService to import data into PDF file
POST URL - http://localhost:4502/content/AemFormsSamples/mergedata.html
Request Parameters:
Export Data from PDF File
Use FormsService to export data from PDF File
POST URL - http://localhost:4502/content/AemFormsSamples/exportdata.html
Request Parameters:
You could import this postman collection to test the API