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

Do you need to process or display PDF files?

Find out why you should be using IDRSolutions software

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.

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



Our software libraries allow you to

Convert PDF files to HTML
Use PDF Forms in a web browser
Convert PDF Documents to an image
Work with PDF Documents in Java
Read and write HEIC and other Image formats in Java
suda Senior Java EE Develope specialises in Pdf forms , Fonts, application servers and Image manipulation, meditates in spare time.

How to insert an image into a PDF

Recently, we released JPedal 2023.07 which contains the ability to insert images into PDF files. All you need is a copy of JPedal, a...
Jacob Collins
18 sec read

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.

Comments are closed.