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
  • 12461 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

April 12, 2005
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
April 12, 2005
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?
April 12, 2005
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'.
April 12, 2005
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.
April 20, 2005
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.
April 21, 2005
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
August 5, 2005
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 ..
August 5, 2005
You need to do a Response.Write() for the XML part as well.
August 5, 2005
No good on that,

It's almost like the xpath to the data is not right
August 26, 2005
Garth do you have a sample file of this. i would like to see it in action. Thanks george@skyemark.com