Skip navigation
This discussion is locked
Currently Being Moderated

Submit the form XML to a URL over HTTP

Mar 29, 2012 6:31 AM

Tags: #form #submit_form #pdf_forms #acrobat_forms #form_submission #submit_url #submit_xml

Hi,

 

I need tips on how to use Submit to URL functionality on the form .

 

I want the form xml to be submitted to a URL . I understand that there will be a button on the form on which i can specilfy the URL .

 

But how on the other end i can retrieve that xml and use it ? Can anybody help me with the sample code .

 

Thanks

 

Message was edited by: ashish gupta. to make the title more descriptive.

 
Replies
  • Currently Being Moderated
    Dec 20, 2010 9:51 AM   in reply to amateur85

    What kind of technology are you running on the server?

     

    If you are Microsoft-centric with an IIS HTTP server you probably should consider an ASP server-side. If you are Java-centric with Apache, Tomcat, JBoss, for example, you should probably consider a JSP (Java server page) or a Java servlet server-side. Or maybe you are running Apache and PHP.

     

    Steve

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 20, 2010 10:19 PM   in reply to amateur85

    If you are unfamiliar with Java this may be a challenge. The servlet below uses the Java IO package to convert the servlet input stream to a string buffer to a string. The DOM4J XML parser is then used to convert the string to an XML document. The servlet writes the XML document to c:\\pdf.xml and sends an HTML response back to the browser (and Preview in Designer which is actually an HTML container) indicating "The XML data was successfully written to c://pdf.xml." A sample pdf.xml is attached.

     

    NOTE: You cannot submit data from the attached PDF in Reader or Acrobat stand-alone. The PDF has to be opened in a browser. Additional scripting is required to submit data from a PDF in Reader or Acrobat stand-alone.

     

    From LiveCycle Designer Preview I can fill the form with data and hit the Submit button resulting a call to the servlet.

     

    Untitled.png

     

    The servlet responds with HTML which is written in the browser container.

     

    Untitled1.png

    Untitled2.png

     

    DOM4J is the simplest of the XML parsers for the task. You will need to use a Java IDE such as Eclipse to configure a project to use the Java APIs, the servlet APIs and DOM4J. Alternatively you can use a good old fashioned text editor and a batch file to compile the Java class.

     

     

    import java.io.IOException;

    import java.io.InputStream;

    import java.io.FileOutputStream;

    import java.io.PrintWriter;

     

    import javax.servlet.ServletException;

    import javax.servlet.http.HttpServlet;

    import javax.servlet.http.HttpServletRequest;

    import javax.servlet.http.HttpServletResponse;

     

    import org.dom4j.Document;

    import org.dom4j.DocumentHelper;

    import org.dom4j.DocumentException;

    import org.dom4j.io.OutputFormat;

    import org.dom4j.io.XMLWriter;

     

    public class ReadAndWriteXml extends HttpServlet {

     

     

    private static final long serialVersionUID = 1L;

     

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

         doPost(req,resp);

    }

     

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

         try {

              InputStream inputStream = req.getInputStream();

              StringBuffer stringBuffer = new StringBuffer();

              byte[] bytes = new byte[4096];

              for (int n; (n = inputStream.read(bytes)) != -1;) {

                   stringBuffer.append(new String(bytes, 0, n));

              }

              String xmlStr = new String(stringBuffer.toString());

              String filePath = "C://pdf.xml";

              FileOutputStream fileOutputStream = new FileOutputStream(filePath);

              OutputFormat format = OutputFormat.createPrettyPrint();

              XMLWriter xmlWriter = new XMLWriter(fileOutputStream, format);

              xmlWriter.write(convertString2Document(xmlStr));

              xmlWriter.flush();

     

              resp.setContentType("text/html");

              PrintWriter out = resp.getWriter();

              out.println("<html><body><center>");

              out.println("<p>The XML data was successfully written to c://pdf.xml.</p>");

              out.println("</center></body></html>");

         }

         catch (Exception e) {

              System.out.println("The following exception occurred: "+ e.getMessage());

         }

    }

     

    public Document convertString2Document(String xml) throws DocumentException {

         Document document = null;

         try {

              document = DocumentHelper.parseText(xml);

         }

         catch (DocumentException e) {

              e.printStackTrace();

         }

         return document;

    }

     

    }

     

    Steve

    Attachments:
     
    |
    Mark as:
  • Currently Being Moderated
    Jan 18, 2012 10:12 PM   in reply to amateur85

    HI ,

    Can we send the entire PDF?How?I am using dot net at server side.

     

    Thanks ,

    Leena

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points