Passing Documents to the Forms Service passing-documents-to-the-formsservice
Samples and examples in this document are only for AEM Forms on JEE environment.
The AEM Forms service renders interactive PDF forms to client devices, typically web browsers, to collect information from users. An interactive PDF form is based on a form design that is typically saved as an XDP file and created in Designer. As of AEM Forms, you can pass a com.adobe.idp.Document object that contains the form design to the Forms service. The Forms service then renders the form design in the com.adobe.idp.Document object.
An advantage of passing a com.adobe.idp.Document object to the Forms service is that other service operations return a com.adobe.idp.Document instance. That is, you can get a com.adobe.idp.Document instance from another service operation and render it. For example, assume that an XDP file is stored in a Content Services (deprecated) node named /Company Home/Form Designs, as shown in the following illustration.
You can programmatically retrieve Loan.xdp from Content Services (deprecated) (deprecated) and pass the XDP file to the Forms service within a com.adobe.idp.Document object.
Summary of steps summary-of-steps
To pass a document obtained from Content Services (deprecated) (deprecated) to the Forms service, perform the following tasks:
- Include project files.
- Create a Forms and a Document Management Client API object.
- Retrieve the form design from Content Services (deprecated).
- Render the interactive PDF form.
- Perform an action with the form data stream.
Include project files
Include the necessary files in your development project. If you are creating a client application by using Java, include the necessary JAR files. If you are using web services, include the proxy files.
Create a Forms and a Document Management Client API object
Before you can programmatically perform a Forms service API operation, create a Forms Client API object. Also, because this workflow retrieves an XDP file from Content Services (deprecated), create a Document Management API object.
Retrieve the form design from Content Services (deprecated)
Retrieve the XDP file from Content Services (deprecated) by using the Java or web service API. The XDP file is returned within a com.adobe.idp.Document instance (or a BLOB instance if you are using web services). You can then pass the com.adobe.idp.Document instance to the Forms service.
Render an interactive PDF form
To render an interactive form, pass the com.adobe.idp.Document instance that was returned from Content Services (deprecated) to the Forms service.
com.adobe.idp.Document that contains the form design to the Forms service. Two new methods named renderPDFForm2 and renderHTMLForm2 accept a com.adobe.idp.Document object that contains a form design.Perform an action with the form data stream
Depending on the type of client application, you can write the form to a client web browser or save the form as a PDF file. A web-based application typically writes the form to web browser. However, a desktop application typically saves the form as a PDF file.
See also
Pass documents to the Forms Service using the Java API pass-documents-to-the-forms-service-using-the-java-api
Pass a document obtained from Content Services (deprecated) by using the Forms service and Content Services (deprecated) API (Java):
-
Include project files
Include client JAR files, such as adobe-forms-client.jar and adobe-contentservices-client.jar, in your Java project’s class path.
-
Create a Forms and a Document Management Client API object
- Create a
ServiceClientFactoryobject that contains connection properties. (See Setting connection properties.) - Create an
FormsServiceClientobject by using its constructor and passing theServiceClientFactoryobject. - Create a
DocumentManagementServiceClientImplobject by using its constructor and passing theServiceClientFactoryobject.
- Create a
-
Retrieve the form design from Content Services (deprecated)
Invoke the
DocumentManagementServiceClientImplobject’sretrieveContentmethod and pass the following values:- A string value that specifies the store where the content is added. The default store is
SpacesStore. This value is a mandatory parameter. - A string value that specifies the fully qualified path of the content to retrieve (for example,
/Company Home/Form Designs/Loan.xdp). This value is a mandatory parameter. - A string value that specifies the version. This value is an optional parameter, and you can pass an empty string. In this situation, the latest version is retrieved.
The
retrieveContentmethod returns aCRCResultobject that contains the XDP file. Obtain acom.adobe.idp.Documentinstance by invoking theCRCResultobject’sgetDocumentmethod. - A string value that specifies the store where the content is added. The default store is
-
Render an interactive PDF form
Invoke the
FormsServiceClientobject’srenderPDFForm2method and pass the following values:- A
com.adobe.idp.Documentobject that contains the form design retrieved from Content Services (deprecated). - A
com.adobe.idp.Documentobject that contains data to merge with the form. If you do not want to merge data, pass an emptycom.adobe.idp.Documentobject. - A
PDFFormRenderSpecobject that stores run-time options. This value is an optional parameter, and you can specifynullif you do not want to specify run-time options. - A
URLSpecobject that contains URI values. This value is an optional parameter, and you can specifynull. - A
java.util.HashMapobject that stores file attachments. This value is an optional parameter, and you can specifynullif you do not want to attach files to the form.
The
renderPDFFormmethod returns aFormsResultobject that contains a form data stream that must be written to the client web browser. - A
-
Perform an action with the form data stream
- Create a
com.adobe.idp.Documentobject by invoking theFormsResultobject ‘sgetOutputContentmethod. - Get the content type of the
com.adobe.idp.Documentobject by invoking itsgetContentTypemethod. - Set the
javax.servlet.http.HttpServletResponseobject’s content type by invoking itssetContentTypemethod and passing the content type of thecom.adobe.idp.Documentobject. - Create a
javax.servlet.ServletOutputStreamobject used to write the form data stream to the client web browser by invoking thejavax.servlet.http.HttpServletResponseobject’sgetOutputStreammethod. - Create a
java.io.InputStreamobject by invoking thecom.adobe.idp.Documentobject’sgetInputStreammethod. - Create a byte array and populate it with the form data stream by invoking the
InputStreamobject’sreadmethod. Pass the byte array as an argument. - Invoke the
javax.servlet.ServletOutputStreamobject’swritemethod to send the form data stream to the client web browser. Pass the byte array to thewritemethod.
- Create a
See also
Quick Start (SOAP mode): Passing documents to the Forms Service using the Java API
Pass documents to the Forms Service using the web service API pass-documents-to-the-forms-service-using-the-web-service-api
Pass a document obtained from Content Services (deprecated) by using the Forms service and Content Services (deprecated) API (web service):
-
Include project files
Create a Microsoft .NET project that uses MTOM. Because this client application invokes two AEM Forms services, create two service references. Use the following WSDL definition for the service reference associated with the Forms service:
http://localhost:8080/soap/services/FormsService?WSDL&lc_version=9.0.1.Use the following WSDL definition for the service reference associated with the Document Management service:
http://localhost:8080/soap/services/DocumentManagementService?WSDL&lc_version=9.0.1.Because the
BLOBdata type is common to both service references, fully qualify theBLOBdata type when using it. In the corresponding web service quick start, allBLOBinstances are fully qualified.note note NOTE Replace localhostwith the IP address of the server hosting AEM Forms. -
Create a Forms and a Document Management Client API object
-
Create a
FormsServiceClientobject by using its default constructor. -
Create a
FormsServiceClient.Endpoint.Addressobject by using theSystem.ServiceModel.EndpointAddressconstructor. Pass a string value that specifies the WSDL to the AEM Forms service (for example,http://localhost:8080/soap/services/FormsService?WSDL). You do not need to use thelc_versionattribute. This attribute is used when you create a service reference.) -
Create a
System.ServiceModel.BasicHttpBindingobject by getting the value of theFormsServiceClient.Endpoint.Bindingfield. Cast the return value toBasicHttpBinding. -
Set the
System.ServiceModel.BasicHttpBindingobject’sMessageEncodingfield toWSMessageEncoding.Mtom. This value ensures that MTOM is used. -
Enable basic HTTP authentication by performing the following tasks:
- Assign the AEM forms user name to the field
FormsServiceClient.ClientCredentials.UserName.UserName. - Assign the corresponding password value to the field
FormsServiceClient.ClientCredentials.UserName.Password. - Assign the constant value
HttpClientCredentialType.Basicto the fieldBasicHttpBindingSecurity.Transport.ClientCredentialType.
- Assign the AEM forms user name to the field
-
Assign the constant value
BasicHttpSecurityMode.TransportCredentialOnlyto the fieldBasicHttpBindingSecurity.Security.Mode.
note note NOTE Repeat these steps for the DocumentManagementServiceClientservice client. -
-
Retrieve the form design from Content Services (deprecated)
Retrieve content by invoking the
DocumentManagementServiceClientobject’sretrieveContentmethod and passing the following values:- A string value that specifies the store where the content is added. The default store is
SpacesStore. This value is a mandatory parameter. - A string value that specifies the fully qualified path of the content to retrieve (for example,
/Company Home/Form Designs/Loan.xdp). This value is a mandatory parameter. - A string value that specifies the version. This value is an optional parameter, and you can pass an empty string. In this situation, the latest version is retrieved.
- A string output parameter that stores the browse link value.
- A
BLOBoutput parameter that stores the content. You can use this output parameter to retrieve the content. - A
ServiceReference1.MyMapOf_xsd_string_To_xsd_anyTypeoutput parameter that stores content attributes. - A
CRCResultoutput parameter. Instead of using this object, you can use theBLOBoutput parameter to obtain the content.
- A string value that specifies the store where the content is added. The default store is
-
Render an interactive PDF form
Invoke the
FormsServiceClientobject’srenderPDFForm2method and pass the following values:- A
BLOBobject that contains the form design retrieved from Content Services (deprecated). - A
BLOBobject that contains data to merge with the form. If you do not want to merge data, pass an emptyBLOBobject. - A
PDFFormRenderSpecobject that stores run-time options. This value is an optional parameter, and you can specifynullif you do not want to specify run-time options. - A
URLSpecobject that contains URI values. This value is an optional parameter, and you can specifynull. - A
Mapobject that stores file attachments. This value is an optional parameter, and you can specifynullif you do not want to attach files to the form. - A long output parameter that is used to store the page count.
- A string output parameter that is used to store the locale value.
- A
FormsResultoutput parameter that is used to store the interactrive PDF form.
The
renderPDFForm2method returns aFormsResultobject that contains the interactive PDF form. - A
-
Perform an action with the form data stream
- Create a
BLOBobject that contains form data by getting the value of theFormsResultobject’soutputContentfield. - Create a
System.IO.FileStreamobject by invoking its constructor. Pass a string value that represents the file location of the interactive PDF document and the mode in which to open the file. - Create a byte array that stores the content of the
BLOBobject retrieved from theFormsResultobject. Populate the byte array by getting the value of theBLOBobject’sMTOMdata member. - Create a
System.IO.BinaryWriterobject by invoking its constructor and passing theSystem.IO.FileStreamobject. - Write the contents of the byte array to a PDF file by invoking the
System.IO.BinaryWriterobject’sWritemethod and passing the byte array.
- Create a
See also