Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Populate PDF form with XML data

Avatar

Former Community Member
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 :-(.
38 Replies

Avatar

Former Community Member
Hey Garth,<br /><br />I too struggled with that for over a day and finally got it to work. Do this:<br /><br />1. Create your form in Adobe Designer. Save the pdf form and Close.<br />2. Open Adobe and put data in each field you created. Then click on File, Form Data, Export Data from Form and save to an XML form. Close the pdf.<br />3. Go back to Adobe Designer and open the pdf. If your Data View windows isn't showing... Click on Window, Data View.<br />4. Right click on the Data View pane and click on New Data Connection. You can use the default connection name. Choose the Sample XML Data radio button and then Next. Locate the file that you exported in step 2. Then Click Finish. All your field names should be in the Data View.<br />5. On each of your fields, click on the binding tab. Then click on the arrow beside the Default Binding... navigate to DataConnection... and go through your subform(s) to find the field name you want to bind to.<br />6. Save the pdf. <br />7. Now to ASP:<br /><br />Here is a sample subroutine using a test.pdf with two text fields.<br /><br />Sub writeBody<br />Response.ContentType = "application/vnd.adobe.xdp+xml" %><?xml version="1.0" encoding="UTF-8"?> <br /><?xfa generator="AdobeDesigner_V7.0" APIVersion="2.2.4333.0"?> <br /><xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/"> <br /><xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"> <br /><xfa:data xfa:dataNode="dataGroup"><br /><form1><br /><subform1><br /><TextField1>Test 1</TextField1><br /><TextField2>Test 2</TextField2><br /></subform1><br /></form1><br /></xfa:data> <br /></xfa:datasets> <br /><pdf href="http://www.somewhere.com/test.pdf" xmlns="http://ns.adobe.com/xdp/pdf/" /> <br /><xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve" > <br /><annots/> <br /></xfdf> <br /></xdp:xdp><br /><%<br />End Sub<br /><br />I hope this helps. FDF was A LOT easier but I'm having to convert my FDF logic to XML to keep up with the 7.0 Reader. I finally figured out how to take the posted data and convert it back to XML so it can be saved and reloaded back into the form if needed. Let me know if you want some sample code.<br /><br />Good Luck!<br />Floyd

Avatar

Former Community Member
Thanks Floyd; that was the path I was starting to take but realized that I would have to map each and every field and rewrite the asp page to assign the values to each field (textfield1 & textfield2 in your example). While this may work, how does one maintain the integrity of your original data XML? Put another way, is there a way to import your XML data into the form fields so that the presentation (PDF) is separate from the data (XML)?<br /><br />For example...Say I have the following XML file (simplified):<br /><br /><xml><br /><group><br /><dataitem>value</dataitem><br /><dataitem>value</dataitem><br /><dataitem>value</dataitem><br /><dataitem>value</dataitem><br /></group><br /></xml><br /><br />And within my Designer Form I have four text fields (A, B, C, D). Each of those has a binding pointing to $record.group.dataitem[*]. Which, again, works with the preview function in Designer.<br /><br />Now when I load the asp page can I just import that XML file? Something like (using your example above):<br /><br /><% Sub writeBody <br />Response.ContentType = "application/vnd.adobe.xdp+xml" %><?xml version="1.0" encoding="UTF-8"?> <br /><?xfa generator="AdobeDesigner_V7.0" APIVersion="2.2.4333.0"?> <br /><xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/"> <br /><xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"> <br /><xfa:data xfa:dataNode="dataGroup"><br /><br /><!-- Insert/Reference XML data here... --><br /><br /></xfa:data> <br /></xfa:datasets> <br /><pdf href="http://www.somewhere.com/test.pdf" xmlns="http://ns.adobe.com/xdp/pdf/" /> <br /><xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve" > <br /><annots/> <br /></xfdf> <br /></xdp:xdp> <br /><% End Sub %><br /><br />Does that make sense? I kind of figured that since the PDF already has the binding information it should be able to pick the appropriate nodes from the XML file and populate the information, rather than me iterating through my data set and assigning values to each field. Is this possible?

Avatar

Former Community Member
Sorry, looks like the message posts html :-P. That big space in the last bit of example code above, right before should have a line that reads 'Import/Reference XML data file here'.

Avatar

Former Community Member
Hey Garth. The orignal data XML that I used was just dummy data so the designer would put the proper data tags in the pdf. My ASP saves the data from the post operation in a new XML file. Your import should work but make sure it is structured exactly like the export XML. It should start with something like ..... or it won't map to the proper fields.

Avatar

Former Community Member
Thanks again Floyd. Just so we can close the loop on this and hopefully prevent others from experiencing the same frustration I had, here is the entire problem + solution:<br /><br />b The Problem:<br /><br />One wants to have a web download pdf created with Adobe Designer that will import or populate fields within the pdf with XML data using ASP or ASP.Net, etc.<br /><br />b The Solution: <br /><br />1. Create the pdf form with Designer, placing all fields/text boxes as appropriate.<br /><br />2. Use the data binding feature to assign values from a sample XML document to the fields and use the preview pdf feature to make sure everything is working properly.<br /><br />3. Assign any security settings to the document and save as a dynamic PDF.<br /><br />4. Create the ASP page that users will use to download your PDF. Your code may vary, but the page must contain the following:<br /><br /> (a) The response type must be of type "application/vnd.adobe.xdp+xml"<br /><br /> (b) The very first line must be: "<?xml version=""1.0"" encoding=""UTF-8""?>", so you may need to do a response.write or a sub that generates the response or it won't work.<br /><br /> (c) Then the following:<br /><?xfa generator="AdobeDesigner_V7.0" APIVersion="2.2.4333.0"?> <br /><xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/"> <br /><xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"> <br /><xfa:data xfa:dataNode="dataGroup"><br /><br /> (d) Here you insert the XML, WITHOUT the <xml> header or end tag. This should be in exactly the same format as the XML you used to test. I use an include file to get the XML file and strip the <xml> header and end tag.<br /><br /> (e) Now you must point to the pdf file and end the XML, like so:<br /></xfa:data> <br /></xfa:datasets><br /><pdf href="http://yourdomain.com/yourpdffile.pdf" xmlns="http://ns.adobe.com/xdp/pdf/" /> <br /><xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve" > <br /><annots/> <br /></xfdf> <br /></xdp:xdp><br /><br /> (f) Finally, do a Response.Flush and Response.End to spit out the file.<br /><br />Now, just publish the pdf file, the asp file and the xml file and you should be all set.

Avatar

Former Community Member
Need a consultant/programmer that is familiar with dynamic pdf forms. We need to be able to have a pdf form client side and as data is entered, other form data is looked up from a sql database on a webserver and automatically filled in - for example if you fill in your zip code, it looks up your city and state - if you fill in your student id, it looks up your name, address phone, etc - if you fill in your degree program, it looks up the total hours and tuition - you get the idea??



Once you're done filling out the form there is also new data that will be stored in the database. It is my understanding that this can be done with LiveCycle, Java, XML, ColdFusion, SQL???



Please email me if you have any input or you can contribute as a consultant or programmer, we're willing to pay the right person or people.



Thanks!!

Cynthia

chebultz@tstar.net

Avatar

Former Community Member
Well I cant seem to get past some problem<br />The asp page brings up the pdf file but the data does not seem to load <br />any one have any ideas <br />here is my asp <br /><br /><%Response.ContentType = "application/vnd.adobe.xdp+xml" %><br /><%response.write "<?xml version='1.0' encoding='UTF-8'?>" %><br /><%response.write "<?xfa generator='AdobeDesigner_V7.0' APIVersion='2.2.4333.0'?> " %><br /><xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/"> <br /><xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"> <br /><xfa:data> <br /><form1><TextField1>test a</TextField1></form1><br /></xfa:data> <br /></xfa:datasets> <br /><pdf href="http://myurl.com/xfdf_test.pdf" xmlns="http://ns.adobe.com/xdp/pdf/" /> <br /><xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve" > <br /><annots/> <br /></xfdf> <br /></xdp:xdp><br /><%response.flush%><%response.end%><br /><br />and the pdf is just a simple text box ..

Avatar

Former Community Member
You need to do a Response.Write() for the XML part as well.

Avatar

Former Community Member
No good on that,

It's almost like the xpath to the data is not right

Avatar

Former Community Member
Garth do you have a sample file of this. i would like to see it in action. Thanks george@skyemark.com

Avatar

Former Community Member
Is there a way using this technique to put items (more than one) in dropdown lists ?

Avatar

Former Community Member
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.

Avatar

Former Community Member
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?

Avatar

Former Community Member
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

Avatar

Former Community Member
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.

Avatar

Former Community Member
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.

Avatar

Former Community Member
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?

Avatar

Former Community Member
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.

Avatar

Former Community Member
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 />>

Avatar

Former Community Member
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);

}

}