suda Senior Java EE Develope specialises in Pdf forms , Fonts, application servers and Image manipulation, meditates in spare time.

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

2 min read

XFA_iconAt IDR Solutions I spend a lot of time working on XFA for our Java PDF Library and PDF to HTML5 Converter and during this time I learned a lot of interesting 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 form 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 attributes 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 the event section 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 a 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 a simple servlet called ProcessXFA in a project named as XFATest; This servlet outputs the request details in the 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.



Are you a Developer working with PDF files?

Our developers guide contains a large number of technical posts to help you understand the PDF file Format.

Find out more about our software for Developers

suda Senior Java EE Develope specialises in Pdf forms , Fonts, application servers and Image manipulation, meditates in spare time.

One Reply to “Editing XFA files in Adobe LifeCycle to allow direct…”

  1. 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 *

IDRsolutions Ltd 2021. All rights reserved.