AEM 6.4 has reached the end of extended support and this documentation is no longer updated. For further details, see our technical support periods. Find the supported versions here.
The Forms service renders interactive PDF forms to client devices, typically web browsers, to collect information from users. After an interactive form is rendered, a user can enter data into form fields and click a submit button located on the form to send information back to the Forms service. Adobe Reader or Acrobat must be installed on the computer hosting the client web browser in order for an interactive PDF form to be visible.
Before you can render a form using the Forms service, create a form design. Typically, a form design is created in Designer and is saved as an XDP file. For information about creating a form design, see Forms Designer.
Sample loan application
A sample loan application is introduced to demonstrate how the Forms service uses interactive forms to collect information from users. This application lets a user fill in a form with data required to secure a loan and then submits data to the Forms service. The following diagram shows the loan application’s logic flow.
The following table describes the steps in this diagram.
Step |
Description |
---|---|
1 |
The |
2 |
The |
3 |
After the user fills the loan form and clicks the submit button, data is submitted to the |
4 |
The |
5 |
A confirmation form is rendered back to the web browser. Data such as the user’s first and last name is merged with the form before it is rendered. (See Prepopulating Forms with Flowable Layouts.) |
Loan form
This interactive loan form is rendered by the sample loan application’s GetLoanForm
Java Servlet.
Confirmation form
This form is rendered by the sample loan application’s HandleData
Java Servlet.
The HandleData
Java Servlet prepopulates this form with the user’s first and last name as well as the amount. After the form is prepopulated, it is sent to the client web browser. (See Prepopulating Forms with Flowable Layouts)
Java Servlets
The sample loan application is an example of a Forms service application that exists as a Java Servlet. A Java Servlet is a Java program running on a J2EE application server, such as WebSphere, and contains Forms service Client API code.
The following code shows the syntax of a Java Servlet named GetLoanForm:
public class GetLoanForm extends HttpServlet implements Servlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp
throws ServletException, IOException {
}
public void doPost(HttpServletRequest req, HttpServletResponse resp
throws ServletException, IOException {
}
Normally, you would not place Forms service Client API code within a Java Servlet’s doGet
or doPost
method. It is better programming practice to place this code within a separate class, instantiate the class from within the doPost
method (or doGet
method), and call the appropriate methods. However, for code brevity, the code examples in this section are kept to a minimum and code examples are placed in the doPost
method.
For more information about the Forms service, see Services Reference for AEM Forms.
Summary of steps
To render an interactive PDF form, perform the following tasks:
Include project files
Include necessary files into your development project. If you are creating a client application using Java, include the necessary JAR files. If you are using web services, ensure that you include the proxy files.
Create a Forms Client API object
Before you can programmatically perform a Forms service Client API operation, you must create a Forms Client API object. If you are using the Java API, create a FormsServiceClient
object. If you are using the Forms web service API, create a FormsService
object.
Specify URI values
You can specify URI values that are required by the Forms service to render a form. A form design that is saved as part of a Forms application can be referenced by using the content root URI value repository:///
. For example, consider the following form design named Loan.xdp located within a Forms application named FormsApplication:
To access this form design, specify Applications/FormsApplication/1.0/FormsFolder/Loan.xdp
as the form name (the first parameter passed to the renderPDFForm
method) and repository:///
as the content root URI value.
For information about creating a Forms application using Workbench, see Workbench Help.
The path to a resource located in a Forms application is:
Applications/Application-name/Application-version/Folder.../Filename
The following values show some examples of URI values:
When you render an interactive form, you can define URI values such as the target URL to where form data is posted. The target URL can be defined in one of the following ways:
If the target URL is defined within the form design, do not override it with the Forms service Client API. That is, setting the target URL using the Forms API resets the specified URL in the form design to the one specified using the API. If you wish to submit the PDF form to the target URL specified in the form design, then programmatically set the target URL to an empty string.
If you have a form that contains a submit button and a calculate button (with a corresponding script that runs at the server), you can programmatically define the URL to where the form is sent to execute the script. Use the submit button on the form design to specify the URL to where form data is posted. (See Calculating Form Data.)
Instead of specifying a URL value to reference a XDP file, you can also pass a com.adobe.idp.Document
instance to the Forms service. The com.adobe.idp.Document
instance contains a form design. (See Passing Documents to the Forms Service.)
Attach files to the form
You can attach files to a form. When you render a PDF form with file attachments, users can retrieve the file attachments in Acrobat using the file attachment pane. You can attach different file types to a form, such as a text file, or to a binary file such as a JPG file.
Attaching file attachments to a form is optional.
Render an interactive PDF form
To render a form, use a form design that was created in Designer and saved as an XDP or PDF file. As well, you can render a form that was created using Acrobat and saved as a PDF file. To render an interactive PDF form, invoke the FormsServiceClient
object’s renderPDFForm
method or renderPDFForm2
method.
The renderPDFForm
uses a URLSpec
object. The content root to the XDP file is passed to the Forms service using the URLSpec
object’s setContentRootURI
method. The Form design name ( formQuery
) is passed as a separate parameter value. The two values are concatenated to get the absolute reference to the form design.
The renderPDFForm2
method accepts a com.adobe.idp.Document
instance that contains the XDP or PDF document to render.
The tagged PDF run-time option cannot be set if the input document is a PDF document. If the input file is an XDP file, the tagged PDF option can be set.
Render an interactive PDF form by using the Forms API (Java):
Include project files
Include client JAR files, such as adobe-forms-client.jar, in your Java project’s class path.
Create a Forms Client API object
ServiceClientFactory
object that contains connection properties.FormsServiceClient
object by using its constructor and passing the ServiceClientFactory
object.Specify URI values
URLSpec
object that stores URI values by using its constructor.URLSpec
object’s setApplicationWebRoot
method and pass a string value that represents the application’s web root.URLSpec
object’s setContentRootURI
method and pass a string value that specifies the content root URI value. Ensure that the form design is located in the content root URI. If not, the Forms service throws an exception. To reference the repository, specify repository:///
.URLSpec
object’s setTargetURL
method and pass a string value that specifies the target URL value to where form data is posted. If you define the target URL in the form design, you can pass an empty string. You can also specify the URL to where a form is sent in order to perform calculations.Attach files to the form
Create a java.util.HashMap
object to store file attachments by using its constructor.
Invoke the java.util.HashMap
object’s put
method for each file to attach to the rendered form. Pass the following values to this method:
A com.adobe.idp.Document
object that contains the file attachment.
Repeat this step for each file to attach to the form. This step is optional and you can pass null
* if you do not want to send file attachments.*
Render an interactive PDF form
Invoke the FormsServiceClient
object’s renderPDFForm
method and pass the following values:
Applications/FormsApplication/1.0/FormsFolder/Loan.xdp
.com.adobe.idp.Document
object that contains data to merge with the form. If you do not want to merge data, pass an empty com.adobe.idp.Document
object.PDFFormRenderSpec
object that stores run-time options. This is an optional parameter and you can specify null
if you do not want to specify run-time options.URLSpec
object that contains URI values that are required by the Forms service.java.util.HashMap
object that stores file attachments. This is an optional parameter and you can specify null
if you do not want to attach files to the form.The renderPDFForm
method returns a FormsResult
object that contains a form data stream that must be written to the client web browser.
Write the form data stream to the client web browser
com.adobe.idp.Document
object by invoking the FormsResult
object ‘s getOutputContent
method.com.adobe.idp.Document
object by invoking its getContentType
method.javax.servlet.http.HttpServletResponse
object’s content type by invoking its setContentType
method and passing the content type of the com.adobe.idp.Document
object.javax.servlet.ServletOutputStream
object used to write the form data stream to the client web browser by invoking the javax.servlet.http.HttpServletResponse
object’s getOutputStream
method.java.io.InputStream
object by invoking the com.adobe.idp.Document
object’s getInputStream
method.InputStream
object’s read
method and passing the byte array as an argument.javax.servlet.ServletOutputStream
object’s write
method to send the form data stream to the client web browser. Pass the byte array to the write
method.Render an interactive PDF form by using the Forms API (web service):
Include project files
Create a Forms Client API object
Create a FormsService
object and set authentication values.
Specify URI values
URLSpec
object that stores URI values by using its constructor.URLSpec
object’s setApplicationWebRoot
method and pass a string value that represents the application’s web root.URLSpec
object’s setContentRootURI
method and pass a string value that specifies the content root URI value. Ensure that the form design is located in the content root URI. If not, the Forms service throws an exception. To reference the repository, specify repository:///
.URLSpec
object’s setTargetURL
method and pass a string value that specifies the target URL value to where form data is posted. If you define the target URL in the form design, you can pass an empty string. You can also specify the URL to where a form is sent in order to perform calculations.Attach files to the form
Create a java.util.HashMap
object to store file attachments by using its constructor.
Invoke the java.util.HashMap
object’s put
method for each file to attach to the rendered form. Pass the following values to this method:
A BLOB
object that contains the file attachment
Repeat this step for each file to attach to the form.
Render an interactive PDF form
Invoke the FormsService
object’s renderPDFForm
method and pass the following values:
Applications/FormsApplication/1.0/FormsFolder/Loan.xdp
.BLOB
object that contains data to merge with the form. If you do not want to merge data, pass null
.PDFFormRenderSpec
object that stores run-time options. This is an optional parameter and you can specify null
if you do not want to specify run-time options.URLSpec
object that contains URI values that are required by the Forms service.java.util.HashMap
object that stores file attachments. This is an optional parameter and you can specify null
if you do not want to attach files to the form.com.adobe.idp.services.holders.BLOBHolder
object that is populated by the method. This is used to store the rendered PDF form.javax.xml.rpc.holders.LongHolder
object that is populated by the method. (This argument will store the number of pages in the form.)javax.xml.rpc.holders.StringHolder
object that is populated by the method. (This argument will store the locale value.)com.adobe.idp.services.holders.FormsResultHolder
object that will contain the results of this operation.The renderPDFForm
method populates the com.adobe.idp.services.holders.FormsResultHolder
object that is passed as the last argument value with a form data stream that must be written to the client web browser.
Write the form data stream to the client web browser
FormResult
object by getting the value of the com.adobe.idp.services.holders.FormsResultHolder
object’s value
data member.BLOB
object that contains form data by invoking the FormsResult
object’s getOutputContent
method.BLOB
object by invoking its getContentType
method.javax.servlet.http.HttpServletResponse
object’s content type by invoking its setContentType
method and passing the content type of the BLOB
object.javax.servlet.ServletOutputStream
object used to write the form data stream to the client web browser by invoking the javax.servlet.http.HttpServletResponse
object’s getOutputStream
method.BLOB
object’s getBinaryData
method. This task assigns the content of the FormsResult
object to the byte array.javax.servlet.http.HttpServletResponse
object’s write
method to send the form data stream to the client web browser. Pass the byte array to the write
method.Write the form data stream to the client web browser
When the Forms service renders a form, it returns a form data stream that you must write to the client web browser. When written to the client web browser, the form is visible to the user.