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

November 13, 2006
This posting saved me a lot of time and i want to thank everyone that contributed to it.

I have noticed that when the XML data is formatted incorrect, the errors reported are vague and IE browser takes long time to recover from error.

I am still looking for some more information on the possiblity of locking or hiding certain selected fields. In other words, based on a policy I would like to display a PDF document with data filled but the fields locked or hidden so that either user can not edit or can not see. I know that I can do this with the template itself but that is not what I want as this information (about fields locked/hidden) is not static but dynamic and set by an Administrator.

Any useful information regarding this issue will be greatly appreciated.
November 16, 2006
Ravinder, were you actually able to get your PDF Document (Form) to load with data? I have not been able to get my .NET page to populate my PDF document - the PDF loads in my Browser but has no data. If you can post sample code that you were able to get to work, it would be appreciated, or if you notice something wrong with my code below, please let me know.<br /><br />Also, when my PDF document loads in my browser, I am prompted to "Open or Save" my .xdp file and if I click "Open", my PDF Form loads, but the fields are not populated. How do I stop this prompt from loading? I don't want the user(s) to be able to see this.<br /><br />My .NET page and XML file are listed below:<br />------------------------- .NET -----------------------------------<br />Imports System.Text<br />Imports System.IO<br /><br />Public Class WebForm1<br /> Inherits System.Web.UI.Page<br /><br />#Region " Web Form Designer Generated Code "<br /><br /> 'This call is required by the Web Form Designer.<br /> <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br /><br /> End Sub<br /><br /> 'NOTE: The following placeholder declaration is required by the Web Form Designer.<br /> 'Do not delete or move it.<br /> Private designerPlaceholderDeclaration As System.Object<br /><br /> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init<br /> 'CODEGEN: This method call is required by the Web Form Designer<br /> 'Do not modify it using the code editor.<br /> InitializeComponent()<br /> End Sub<br /><br />#End Region<br /><br /> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br /> 'Put user code to initialize the page here<br /><br /> Dim responseString As New StringBuilder<br /> Dim sr As StreamReader<br /> Dim xmldata As String<br /><br /> Response.ContentType = "application/vnd.adobe.xdp+xml"<br /> responseString.Append("<?xml version='1.0' encoding='UTF-8'?>")<br /> responseString.Append("<?xfa generator='AdobeDesigner_V7.0' APIVersion='2.2.4333.0'?>")<br /> responseString.Append("<xdp:xdp xmlns:xdp='http://ns.adobe.com/xdp/'>")<br /> responseString.Append("<xfa:datasets xmlns:xfa='http://www.xfa.org/schema/xfa-data/1.0/'>")<br /> responseString.Append("<xfa:data xfa:dataNode='dataGroup'>")<br /> sr = File.OpenText("c:\\inetpub\\wwwroot\\PDFFiller\\TestForm_data.xml")<br /> xmldata = sr.ReadToEnd()<br /> sr.Close()<br /> responseString.Append(xmldata)<br /><br /> 'responseString.Append("<form1>")<br /> 'responseString.Append("<txtFirstName>Homer</txtFirstName>")<br /> 'responseString.Append("<txtLastName>Simpson</txtLastName>")<br /> 'responseString.Append("</form1>")<br /><br /> responseString.Append("</xfa:data>")<br /> responseString.Append("</xfa:datasets>")<br /> responseString.Append("<pdf href='http://localhost/PDFFiller/TestForm.pdf' xmlns='http://ns.adobe.com/xdp/pdf/' />")<br /> responseString.Append("<xfdf xmlns='http://ns.adobe.com/xfdf/' xml:space='preserve'>")<br /> responseString.Append("<annots/>")<br /> responseString.Append("</xfdf>")<br /> responseString.Append("</xdp:xdp>")<br /><br /> Response.Write(responseString)<br /> Response.Flush()<br /> Response.End()<br /><br /> End Sub<br /><br />End Class<br /><br />----------------------End .NET -----------------------------------<br /><br />--------- XML (TestForm_data.xml) --------------------------------<br /><form1><txtFirstName>Homer</txtFirstName><txtLastName>Simpson</txtLastName></form1><br />----------------------End XML -----------------------------------
November 16, 2006
With a lot of trial and error, here is the revised code that I got to populate my PDF form:<br /><br /> Response.ContentType = "application/vnd.adobe.xdp+xml"<br /> responseString.Append("<?xml version='1.0' encoding='UTF-8'?>")<br /><br /> responseString.Append("<?xfa generator='AdobeDesigner_V7.0' APIVersion='2.2.4333.0'?>")<br /> responseString.Append("<xdp:xdp xmlns:xdp='http://ns.adobe.com/xdp/'>")<br /> responseString.Append("<xfa:datasets xmlns:xfa='http://www.xfa.org/schema/xfa-data/1.0/'>")<br /> responseString.Append("<xfa:data>")<br /><br /> responseString.Append("<form1>")<br /> responseString.Append("<txtFirstName>Homer</txtFirstName>")<br /> responseString.Append("<txtLastName>Simpson</txtLastName>")<br /> responseString.Append("</form1>")<br /><br /> responseString.Append("</xfa:data>")<br /> responseString.Append("</xfa:datasets>")<br /> responseString.Append("<pdf href='http://localhost/PDFFiller/TestForm.pdf' xmlns='http://ns.adobe.com/xdp/pdf/' />")<br /> responseString.Append("</xdp:xdp>")<br /><br /> Response.Write(responseString)<br /> Response.Flush()<br /> Response.End()
Level 7
November 17, 2006
I'm worried.



Is this approach described in any official Adobe documentation? PDF and XDP are open specs, right? Where is all this specified? With which versions of Reader/Acrobat does this work? Can we rely on this approach working in future versions?



The main source of my concern is this. The ability to merge XML data with PDF forms on a server is the main feature of Adobe LiveCycle Forms, a server product that sells for tens of thousands of dollars. Why would Adobe create and support a means of pre-filling forms that doesn't provide any revenue for them? It makes one question the value/purpose of Adobe LiveCycle Forms (the server product).



I see that the PDF packet in this xdp provides the PDF itself by reference. I wonder if you could also provided it as a base-64 encoded string. I wonder too if you could include the XDP template as well. If so, what happens when the XDP template that you include doesn't match up with the PDF node. What does Reader display?



Thanks to all who have contributed to this very useful and thought-provoking thread.



Jared Langdon

www.jlangdon.ca
November 17, 2006
This is in no way an official Adobe Response, just my opinion.



I don't see the ability to things this way taking away from the value of LC Forms at all. LC Forms provides so many more advantages.



- Supportability: What happens if you use this way and go to production and everything dies at some point. Who do you go to for help? You haven't bought any enterprise product, so you don't have a support contract. So you can be pretty screwed.



- Maintainability: LC Forms provides a nice API that allows you to write maintainable code. I'm not sure you can say the same about code that prints a whole bunch of hard coded strings to a response object in anything but simple cases. Not to mention it takes a whole lot longer to code.



- Future Support: What is the XFA spec changes and it makes your code stop working? You have to rewrite your code. If you have Forms then if the spec changes the code in Forms changes and you don't have to rewrite anything.



- Documentation: Short of reading the XFA spec I don't think there is any.



Value add features:



- What if you want to create a PDF that makes a web service or DB call? Using this method you'd have to buy Reader Extensions which can be significantly more expensive. With Forms you could do these server side and not have to buy anything else.



- Forms can output to multiple output formats. Currently only HTML and PDF. But what if a cool new format is added and you want to use it? You can't.



- What if you having digital signatures on your PDF? You need to submit the entire PDF. But what if you want some server logic to run based on other data in the form. How do you get the data from the PDF.



etc, etc, etc.



In the end I think it's a good that this option is available for people who don't have the budget or who are doing very simple things for which an enterprise product would be overkill. I wouldn't expect many people looking for enterprise solutions to choose this route over buying LC Forms (again, just my opinion... maybe I'm wrong..)



Chris

Adobe Enterprise Developer Support
November 17, 2006
Btw, if you guys generate your own XFA like this, you should not be specifying Designer as the xfa generator. Designer is not generating this XFA, you are.



Chris

Adobe Enterprise Developer Support
May 6, 2007
What should be specified if not Designer? Can you provide the the xfa:generate tag should look like?
May 9, 2007
Great Discussion!<br /><br />Another question here tat might be relevant...<br /><br />Is there a way to make an XDP document stand alone? I know XDP requires the <pdf href=""> tag, but what if we want to send the filled out XDP file to someone who does not have access to the href location? Is there a way we can embed the PDF into the XDP so it is a self contained unit?<br /><br />Thanks,<br />Bob