Quick Start (SOAP mode): Handling PDF forms submitted as PDF using the Java API

The following code example handles a form that is submitted as PDF data. The content type value passed to the processFormSubmission method is CONTENT_TYPE=application/pdf . The submitted form is saved as a PDF file named tempPDF.pdf . Also, because the form is submitted as PDF, file attachments can be retrieved. Any file attachments are saved as JPEG files. (See Handling Submitted Forms.)

    * This Java Quick Start uses the following JAR files 
    * 1. adobe-forms-client.jar 
    * 2. adobe-livecycle-client.jar 
    * 3. adobe-usermanager-client.jar 
    * 4. activation.jar (required for SOAP mode) 
    * 5. axis.jar (required for SOAP mode) 
    * 6. commons-codec-1.3.jar (required for SOAP mode) 
    * 7. commons-collections-3.2.jar  (required for SOAP mode) 
    * 8. commons-discovery.jar (required for SOAP mode) 
    * 9. commons-logging.jar (required for SOAP mode) 
    * 10. dom3-xml-apis-2.5.0.jar (required for SOAP mode) 
    * 11. jaxen-1.1-beta-9.jar (required for SOAP mode) 
    * 12. jaxrpc.jar (required for SOAP mode) 
    * 13. log4j.jar (required for SOAP mode) 
    * 14. mail.jar (required for SOAP mode) 
    * 15. saaj.jar (required for SOAP mode) 
    * 16. wsdl4j.jar (required for SOAP mode) 
    * 17. xalan.jar (required for SOAP mode) 
    * 18. xbean.jar (required for SOAP mode) 
    * 19. xercesImpl.jar (required for SOAP mode) 
    *  (Because Forms quick starts are implemented as Java servlets, it is  
    *  not necessary to include J2EE specific JAR files - the Java project 
    *  that contains this quick start is exported as a WAR file which 
    *  is deployed to the J2EE application server) 
    *  These JAR files are located in the following path: 
    * <install directory>/sdk/client-libs/common 
    * For complete details about the location of these JAR files,  
    * see "Including AEM Forms library files" in Programming with AEM forms 
import java.io.IOException; 
import javax.servlet.Servlet; 
import javax.servlet.ServletException; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
import com.adobe.livecycle.formsservice.client.*; 
import java.util.*; 
import java.io.DataInputStream; 
import java.io.File; 
import java.io.InputStream; 
import java.io.PrintWriter; 
import com.adobe.idp.Document; 
import com.adobe.idp.dsc.clientsdk.ServiceClientFactory; 
import com.adobe.idp.dsc.clientsdk.ServiceClientFactoryProperties; 
//Import DOM libraries 
import org.w3c.dom.NodeList; 
import org.w3c.dom.Node; 
import javax.xml.parsers.*; 
public class HandleSubmittedPDFData extends HttpServlet implements Servlet { 
    public void doGet(HttpServletRequest req, HttpServletResponse resp) 
        throws ServletException, IOException { 
    public void doPost(HttpServletRequest req, HttpServletResponse resp) 
        throws ServletException, IOException { 
            PrintWriter pp = resp.getWriter();      
            //Set connection properties required to invoke AEM Forms                                 
            Properties connectionProps = new Properties(); 
            connectionProps.setProperty(ServiceClientFactoryProperties.DSC_DEFAULT_SOAP_ENDPOINT, "jnp://[server]:[port]"); 
            connectionProps.setProperty(ServiceClientFactoryProperties.DSC_SERVER_TYPE, "JBoss"); 
            connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_USERNAME, "administrator"); 
            connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_PASSWORD, "password"); 
            //Create a ServiceClientFactory object 
            ServiceClientFactory myFactory = ServiceClientFactory.createInstance(connectionProps); 
            //Create a FormsServiceClient object 
            FormsServiceClient formsClient = new FormsServiceClient(myFactory);  
            //Get Form data to pass to the processFormSubmission method 
            Document formData = new Document(req.getInputStream());  
            //Set run-time options 
             RenderOptionsSpec processSpec = new RenderOptionsSpec();  
            //Invoke the processFormSubmission method 
            FormsResult formOut = formsClient.processFormSubmission(formData, 
            //Determine if the form contains file attachments 
            //It is assumed that file attachments are JPG files 
            List fileAttachments = formOut.getAttachments();  
            //Create an Iterator object and iterate through  
            //the List object 
            Iterator iter = fileAttachments.iterator();  
            int i = 0 ;  
            while (iter.hasNext()) {  
                Document file = (Document)iter.next();  
                file.copyToFile(new File("C:\\Adobe\tempFile"+i+".jpg")); 
            //Get the processing state 
            short processState = formOut.getAction(); 
            //Determine if the form data is ready to be processed 
            //This code example checks only for submitted data (value is 0) 
            if (processState == 0)  
              //Determine the content type of the data 
              String myContentType = formOut.getContentType(); 
              if (myContentType.equals("application/pdf")){ 
                    //Get the form data 
                    Document myPDFfile = formOut.getOutputContent();  
                    //Create a PDF object 
                    File myPDFFile = new File("C:\\Adobe\tempPDF.pdf"); 
                    //Populate the PDF file 
                    pp.println("<p> The PDF file is saved as C:\\Adobe\tempPDF.pdf") ;  
        catch (Exception e) { 

// Ethnio survey code removed