Render an interactive PDF form using the Java API
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
- Create a
ServiceClientFactory
object that contains connection properties. - Create an
FormsServiceClient
object by using its constructor and passing theServiceClientFactory
object.
- Create a
-
Specify URI values
- Create a
URLSpec
object that stores URI values by using its constructor. - Invoke the
URLSpec
object’ssetApplicationWebRoot
method and pass a string value that represents the application’s web root. - Invoke the
URLSpec
object’ssetContentRootURI
method and pass a string value that specifies the content root URI value. Ensure that the form design is in the content root URI. If not, the Forms service throws an exception. To reference the repository, specifyrepository:///
. - Invoke the
URLSpec
object’ssetTargetURL
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 to perform calculations.
- Create a
-
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’sput
method for each file to attach to the rendered form. Pass the following values to this method:- A string value that specifies the name of the file attachment, including the file name extension.
-
A
com.adobe.idp.Document
object that contains the file attachment.
NOTE
Repeat this step for each file to attach to the form. This step is optional and you can passnull
if you do not want to send file attachments. -
-
Render an interactive PDF form
Invoke the
FormsServiceClient
object’srenderPDFForm
method and pass the following values:- A string value that specifies the form design name, including the file name extension. If you reference a form design that is part of a Forms application, ensure that you specify the complete path, such as
Applications/FormsApplication/1.0/FormsFolder/Loan.xdp
. - A
com.adobe.idp.Document
object that contains data to merge with the form. If you do not want to merge data, pass an emptycom.adobe.idp.Document
object. - A
PDFFormRenderSpec
object that stores run-time options. This is an optional parameter and you can specifynull
if you do not want to specify run-time options. - A
URLSpec
object that contains URI values that are required by the Forms service. - A
java.util.HashMap
object that stores file attachments. This is an optional parameter and you can specifynull
if you do not want to attach files to the form.
The
renderPDFForm
method returns aFormsResult
object that contains a form data stream that must be written to the client web browser. - A string value that specifies the form design name, including the file name extension. If you reference a form design that is part of a Forms application, ensure that you specify the complete path, such as
-
Write the form data stream to the client web browser
- Create a
com.adobe.idp.Document
object by invoking theFormsResult
object 'sgetOutputContent
method. - Get the content type of the
com.adobe.idp.Document
object by invoking itsgetContentType
method. - Set the
javax.servlet.http.HttpServletResponse
object’s content type by invoking itssetContentType
method and passing the content type of thecom.adobe.idp.Document
object. - Create a
javax.servlet.ServletOutputStream
object used to write the form data stream to the client web browser by invoking thejavax.servlet.http.HttpServletResponse
object’sgetOutputStream
method. - Create a
java.io.InputStream
object by invoking thecom.adobe.idp.Document
object’sgetInputStream
method. - Create a byte array and populate it with the form data stream by invoking the
InputStream
object’sread
method and passing the byte array as an argument. - Invoke the
javax.servlet.ServletOutputStream
object’swrite
method to send the form data stream to the client web browser. Pass the byte array to thewrite
method.
- Create a
Render an interactive PDF form using the web service API
Render an interactive PDF form by using the Forms API (web service):
-
Include project files
- Create Java proxy classes that consume the Forms service WSDL.
- Include the Java proxy classes into your class path.
-
Create a Forms Client API object
Create a
FormsService
object and set authentication values. -
Specify URI values
- Create a
URLSpec
object that stores URI values by using its constructor. - Invoke the
URLSpec
object’ssetApplicationWebRoot
method and pass a string value that represents the application’s web root. - Invoke the
URLSpec
object’ssetContentRootURI
method and pass a string value that specifies the content root URI value. Ensure that the form design is in the content root URI. If not, the Forms service throws an exception. To reference the repository, specifyrepository:///
. - Invoke the
URLSpec
object’ssetTargetURL
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 to perform calculations.
- Create a
-
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’sput
method for each file to attach to the rendered form. Pass the following values to this method:- A string value that specifies the name of the file attachment, including the file name extension
-
A
BLOB
object that contains the file attachment
NOTE
Repeat this step for each file to attach to the form. -
-
Render an interactive PDF form
Invoke the
FormsService
object’srenderPDFForm
method and pass the following values:- A string value that specifies the form design name, including the file name extension. If you reference a form design that is part of a Forms application, ensure that you specify the complete path, such as
Applications/FormsApplication/1.0/FormsFolder/Loan.xdp
. - A
BLOB
object that contains data to merge with the form. If you do not want to merge data, passnull
. - A
PDFFormRenderSpec
object that stores run-time options. This is an optional parameter and you can specifynull
if you do not want to specify run-time options. - A
URLSpec
object that contains URI values that are required by the Forms service. - A
java.util.HashMap
object that stores file attachments. This is an optional parameter and you can specifynull
if you do not want to attach files to the form. - An empty
com.adobe.idp.services.holders.BLOBHolder
object that is populated by the method. This is used to store the rendered PDF form. - An empty
javax.xml.rpc.holders.LongHolder
object that is populated by the method. (This argument will store the number of pages in the form.) - An empty
javax.xml.rpc.holders.StringHolder
object that is populated by the method. (This argument will store the locale value.) - An empty
com.adobe.idp.services.holders.FormsResultHolder
object that will contain the results of this operation.
The
renderPDFForm
method populates thecom.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. - A string value that specifies the form design name, including the file name extension. If you reference a form design that is part of a Forms application, ensure that you specify the complete path, such as
-
Write the form data stream to the client web browser
- Create a
FormResult
object by getting the value of thecom.adobe.idp.services.holders.FormsResultHolder
object’svalue
data member. - Create a
BLOB
object that contains form data by invoking theFormsResult
object’sgetOutputContent
method. - Get the content type of the
BLOB
object by invoking itsgetContentType
method. - Set the
javax.servlet.http.HttpServletResponse
object’s content type by invoking itssetContentType
method and passing the content type of theBLOB
object. - Create a
javax.servlet.ServletOutputStream
object used to write the form data stream to the client web browser by invoking thejavax.servlet.http.HttpServletResponse
object’sgetOutputStream
method. - Create a byte array and populate it by invoking the
BLOB
object’sgetBinaryData
method. This task assigns the content of theFormsResult
object to the byte array. - Invoke the
javax.servlet.http.HttpServletResponse
object’swrite
method to send the form data stream to the client web browser. Pass the byte array to thewrite
method.
- Create a
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.
Experience Manager
Espressos & Experience Manager: AEM Forms
Espressos & Experience Manager
Thursday, Mar 6, 7:00 PM UTC
Join Adobe's AEM product team as they highlight AEM Forms' latest innovations, including: the new Gen AI Assistant, Unified Composition with AEM Sites, and new ways to deploy forms through conversations.
RegisterThe Future of Forms: Experience Success Across the Enrollment Journey
Adobe Experience Manager Forms is the conversion engine to fully capitalize on engagement and personalization efforts, yet it’s frequently...
Wed, Mar 19, 2:00 PM PDT (9:00 PM UTC)
Put the Customer at the Center and Build Relationships That Last a Lifetime
First impressions last a lifetime. Great first impressions feel personal, connected, and relevant right from the start. From the first...
Wed, Mar 19, 2:30 PM PDT (9:30 PM UTC)
Connect with Experience League at Summit!
Get front-row access to top sessions, hands-on activities, and networking—wherever you are!
Learn more