Editing XFA files in Adobe LifeCycle to allow direct posting data to a server

XFA_iconAt IDR Solutions I spend alot of time working on XFA for our Java PDF Library and PDF to HTML5 Converter and during this time I learned alot of intresting things.

Did you know that it is also possible to post data directly to a server by editing the XML content in an XFA file using Adobe LifeCycle?

So I have written this simple step by step article to show you how to add this functionality into your XFA files.

Step 1:

Start with the existing XFA forms in LifeCycle (you will need this software to edit the files). Below is the XML for 2 forms objects as an example.

I have created a text field and a text area (in XFA the text area is a text field with multiple attribute set to true) and added the name of the text field as email and text area as comments.

Example:

<field name="email" y="12.7mm" x="9.525mm" w="63.5mm" h="9mm">
    <ui>
        <textEdit>
        </textEdit>
    </ui>
    //other node stuff goes here
</field>
<field name="comments" y="25.4mm" x="9.525mm" w="63.5mm" h="28.575mm">
    <ui>
        <textEdit multiLine="1">
        </textEdit>
    </ui>
    //other node stuff goes here
</field>

Step 2 :

Next we Insert an html submit button and alter the URL in event section in where the server needed data.

<field >
    ..................
    <event name="event__click" activity="click">
        <submit format="urlencoded" textEncoding="UTF-8"     target="http://localhost:8080/XFATest/ProcessXFA"/>
    </event>
    ..................
</field>

Step 3 : 

For the next step we now save the XFA file as a pdf; then we open it as pdf, then insert the data and click submit button.

That will submit the data to your post request handler. This is the code your XFA form handler will try to communicate with on your server.

I have created simple servlet called ProcessXFA in a project named as XFATest; This servlet outputs the request details in browser:

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* @author suda
*/@WebServlet(urlPatterns = {"/ProcessXFA"})
public class ProcessXFA extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            /* TODO output your page here. You may use following sample code. */            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet Process</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Email: " + request.getParameter("email") + "</h1>");
            out.println("<h1>Comment: " + request.getParameter("comments") + "</h1>");
            out.println("</body>");
            out.println("</html>");
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}

Hopefully you have found this information useful. As you can see, it is really easy to enable your XFA files so that they can directly communicate with your servers.

I have been working on converting XFA forms into HTML5 forms and this technique also works well for posting data from any HTML5 forms.

If you’re a first-time reader, or simply want to be notified when we post new articles and updates, you can keep up to date by social media (TwitterFacebook and Google+) or the Blog RSS.

Related Posts:

The following two tabs change content below.

suda

Java EE developer at IDRSolutions
Suda is the Senior Java EE Developer at IDR Solutions, and specialises in XFA, Fonts, True-Type Fonts, application servers and conversions. He is a keen science-fiction fan in his spare time.
suda

About suda

Suda is the Senior Java EE Developer at IDR Solutions, and specialises in XFA, Fonts, True-Type Fonts, application servers and conversions.
He is a keen science-fiction fan in his spare time.

One thought on “Editing XFA files in Adobe LifeCycle to allow direct posting data to a server

  1. Trista

    After looking over a handful of technical blog posts on your blog, I seriously appreciate your way of writing a article. I saved it to my bookmark website list and will be checking back soon.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>