Populate PDF form with XML data | Community
Skip to main content
April 12, 2005

Populate PDF form with XML data

  • April 12, 2005
  • 38 replies
  • 12535 views
Although a seemingly simple task, this question has occupied way too much of my time the last week and I am asking the following out of sheer desperation and frustration.



I have a pdf form created with Designer 7.0. I have a separate XML data file to populate the form with. I can test using the preview in Designer and everything looks great. Now, all I want to do is deploy this pdf to a standard web server (IIS, Windows) such that any visitor to the site (using Reader) is able to open it/view it/print it, with the data there. That's it.



This was easily accomplished using Acrobat 6 by creating an ASP page that output an FDF file which referenced the PDF. Not so with the latest version.



I have downloaded three separate several hundred page documents that do not explain how to accomplish this task simply. So to summarize:



1. Does this task *require* a separate piece of software (Document Server) that was not required before?

2. If Document Server is not required, what are the steps to publish the pdf file and reference the data file?



Please help, extraordinarily frustrated :-(.
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

38 replies

September 13, 2005
Is there a way using this technique to put items (more than one) in dropdown lists ?
September 13, 2005
George: The project I was working on was a real estate rates sheet. Since the products stay the same, but the rates change on a daily basis, it was necessary to have the fixed layout (PDF - for disclosures and such and nice printing), but the ability to change the rates daily (XML - from our DB). Here is the result in action: http://addisonavenue.com/content/cu/rates/HomeLoanRates.asp



Irritatingly (is that a word?), all of our users had to upgrade to version 7 with all of the issues that entails.



Alexandre: Haven't done this in a while, but I imagine that drop down lists should work as well, assuming the data has been mapped appropriately in Designer.
September 13, 2005
well yes it works for one item, the value I put in the xml part that correspond to my dropdown list appears in the form, but I am looking for a way to put more than one value. Is there a sub tag name?
September 15, 2005
Hi there!



I have nearly the same problem like you...



I want to populate a pdf form (created with designer 7)with XML by PHP and open it at client side to print or add other values.



Any idea to do this with PHP instead of ASP ?



Would help me very much...



ciao

Oliver
September 16, 2005
I have attempted to follow the instructions provided by Floyd and Garth, but all I can manage to do is crash Acrobat Reader 7.0.3 when attempting to view the ASP page. Here are the steps I have followed:



Create a new form in Adobe LiveCycle Designer 7.0.041126.0 (trial version).

Add a text box to the form named TextField1.

Create a simple XML data file; it has one element named "data" which contains one element named "TextField1" which contains the text "sample data".

Use File - New Data Connection to load the sample XML data file.

Use the Binding tab for the text field properties to bind the text field to $record.TextField1.

Save the form as a dynamic PDF form.

Using the same ASP code as posted by Floyd Worley, attempt to serve the PDF file with the text field populated with data.

No luck; Acrobat Reader just crashes with an invalid memory access.



The "result in action" posted by Garth works just fine in my browser. I attempted to serve his PDF off my server populated with data (just as a test) and it worked, so this leads me to suspect the problem is with my PDF file, not the ASP page. Could anyone supply me with a simple, *working*, editable PDF form that I could open in LiveCycle Designer to see if there's something I'm doing wrong? I can be reached at dosolkowski[at]buffalocomputergraphics.com. Thanks.
September 16, 2005
Hi David,

When you open up the form in acrobat reader, did you try to export the data in the form as an XDP file (can only be done from Profesionnal) and then opening this XDP file (it should launch the corresponding PDF file merged with the data in the XDP file). If that works and your ASP test doesn't, then your problem is in the ASP part. But beware of livecycle designer, when you get into it, get ready to struggle to tons of problems and bugs.
September 16, 2005
Alexandre,



I only have access to Acrobat Professional 6.0, which doesn't like even the "6.0-compatible" static PDF version of the form, and also cannot save data to XDP format. It only supports FDF or XFDF. However, the XFDF file seems to work quite nicely. Is there any reason why I could not simply generate an XFDF file programmatically to populate the form fields?
September 16, 2005
Actually FDF is to Acrobat forms what XDP is to Livecycle Designer's forms. It is not the same technology. I've already tried using FDF Toolkit with a form made with livecycle designer and it doesn't work.

You can download an evaluation version of Profesionnal 7 I think.
September 26, 2005
This servlet should populate the fields in a designer form "DOS1.pdf (1 mainform named "f", 2 subforms named "t1 and t2" , 3 textfields)<br /><br />If you request the Servlet URL the PDF is shown, but the fields are not populated with data.<br /><br />Has someone an idea, why the data are not filled in?<br /><br />package PDFXmlData;<br /><br />import java.io.*;<br />import javax.servlet.*;<br />import javax.servlet.http.*;<br />import java.util.*;<br /><br />/** merge Acrobat Designer Docoment with <br /> * xml Data file<br /> */<br /><br />public class Merge extends HttpServlet {<br /> public void doGet(HttpServletRequest request,<br /> HttpServletResponse response)<br /> throws ServletException, IOException {<br /> response.setContentType("application/vnd.adobe.xdp+xml");<br /> ServletOutputStream out = response.getOutputStream();<br /> //PrintWriter out = response.getWriter();<br /> out.print("<?xml version=\"1.0\" encoding='UTF-8'?>");<br /> out.print("<?xfa generator=\"AdobeDesigner_V7.0\" APIVersion=\"2.2.4333.0\"?>");<br /> out.print("<xdp:xdp xmlns:xdp=\"http://ns.adobe.com/xdp/\">");<br /> out.print("<xfa:datasets xmlns:xfa=\"http://www.xfa.org/schema/xfa-data/1.0/\">");<br /> out.print("<xfa:data xfa:dataNode=\"dataGroup\">");<br /> out.print("<f>");<br /> out.print("<t1>");<br /> out.print("<Textfeld1>Hallo</Textfeld1>");<br /> out.print("<Textfeld2>Hallo</Textfeld2>");<br /> out.print("</t1>");<br /> out.print("<t2>");<br /> out.print("<Textfeld3>Hallo</Textfeld3>");<br /> out.print("</t2>");<br /> out.print("</f>");<br /> out.print("</xfa:data>");<br /> out.print("</xfa:datasets>");<br /> out.print("<pdf href=\"http://localhost:8080/ADesigner/DOS1.pdf\" xmlns=\"http://ns.adobe.com/xdp/pdf/\" />");<br /> out.print("<xfdf xmlns=\"http://ns.adobe.com/xfdf/\" xml:space=\"preserve\">");<br /> out.print("<annots/>");<br /> out.print("</xfdf>");<br /> out.print("</xdp:xdp>");<br /> //out.flush();<br /> }<br /><br /> public void doPost(HttpServletRequest request,<br /> HttpServletResponse response)<br /> throws ServletException, IOException {<br /> doGet(request, response);<br /> }<br />}<br /><br />*****<br />XML-Data File:<br /><?xml version="1.0" encoding="UTF-8"?><br /><f<br />><t1<br />><Textfeld1<br />>feld 1</Textfeld1<br />><Textfeld2<br />>feld 2</Textfeld2<br />></t1<br />><t2<br />><Textfeld3<br />>feld 3</Textfeld3<br />></t2<br />></f<br />>
September 27, 2005
I looked at the problem one more time and found the error. If I omit then annot-Tag then the data are populated in the form.



In the next step I rewrote the servlet, so that you can name the Datafile as Url Parameter and the servlet sends form an data back to the client. Notice, the name of the pdf is part of the xdp.



package PDFXmlData;



import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

import java.util.*;



/** merge Acrobat Designer Document with

* xml Data file

*/



public class Merge extends HttpServlet {

public void doGet(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("application/vnd.adobe.xdp+xml");



String xmlFileLocation = request.getParameter("xmlFile");

if ( xmlFileLocation == null) {

// Error handling ...

return;

};



String file = getServletContext().getRealPath(xmlFileLocation);

try {

BufferedInputStream in =

new BufferedInputStream(new FileInputStream(file));

ByteArrayOutputStream byteStream =

new ByteArrayOutputStream(512);

int nRead;



while ((nRead = in.read()) != -1) {

byteStream.write(nRead);

}

in.close();



response.setContentLength(byteStream.size());

byteStream.writeTo(response.getOutputStream());

}

catch(IOException ioEx) {

}

}



public void doPost(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {

doGet(request, response);

}

}