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
Hi,<br />i've got similar problem, here is my php code:<br /><br /><?php<br />header("Content-Type='application/vnd.adobe.xdp+xml'");<br />echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";<br />echo "<?xfa generator=\"AdobeDesigner_V7.0\" APIVersion=\"2.2.4333.0\"?>";<br />echo "<xdp:xdp xmlns:xdp=\"http://ns.adobe.com/xdp/\">";<br />echo "<xfa:datasets xmlns:xfa=\"http://www.xfa.org/schema/xfa-data/1.0/\">";<br />echo "<xfa:data>";<br />echo "<TSP301>";<br />echo " < form > ";<br />echo " < text > sampletext < /text > ";<br />echo "< /form >";<br />echo "</TSP301>";<br />echo "</xfa:data>";<br />echo "</xfa:datasets>";<br />echo "<pdf href=\"http://mercury:8080/sample/dane.pdf\" xmlns=\"http://ns.adobe.com/xdp/pdf/\" />";<br />echo "<xfdf xmlns=\"http://ns.adobe.com/xfdf/\" xml:space=\"preserve\" >";<br />echo "<annots/>";<br />echo "</xfdf>";<br />echo "</xdp:xdp>";<br />?><br /><br />also, i've got simplest pdf on the server (Apache 2) with only one text field, and the all i get in firefox or ie is:<br /><br />sampletext<br /><br />it's only a text, it do not open pdf and load it with data but when i get the source of the page i see all this data wich i 'echo' from php script<br /><br />where i make mistake, maybe someone can show me working php code to preload pdf with data<br /><br />£ukasz

Avatar

Former Community Member
hi

I have a Web Page With PDF and asp, and write same example of here but

The asp page brings up the pdf file but the data does not seem to load

The file xdp is good, but not load in my Web PDF when use my asp



Why that problem?



Thanks for your help

Avatar

Former Community Member
Guys:<br />HEre is the code snippet that works. I tried it with ASP.NET and with Acroba Professional 7.0 installed on the local box.<br /> public class WebForm1 : System.Web.UI.Page<br /> {<br /> private void Page_Load(object sender, System.EventArgs e)<br /> {<br /> string temp = "";<br /><br /> StringBuilder responseString = new StringBuilder();<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 /> StreamReader sr = File.OpenText("c:\\inetpub\\wwwroot\\CaptureAcrobat\\PersonalInfo_data.xml");<br /> string xmldata = sr.ReadToEnd();<br /> sr.Close();<br /> responseString.Append(xmldata);<br /> responseString.Append("</xfa:data>");<br /> responseString.Append("</xfa:datasets>");<br /> responseString.Append("<pdf href='http://localhost/CaptureAcrobat/PersonalInfo.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 /><br />}

Avatar

Former Community Member
lakshmin Ramakrishnan,



Could you help me a little here? I followed your Dot.NET code. Also created PDF and xml files. However, when I viewed the aspx file, I got some xml parse error message and did't see the pdf either.



I must missed something. Your help will be very appreciated!!!

Thanks in advance.

Jie

Avatar

Former Community Member
I could not agree more! I have been so frustrated just tring to populate a PDF with XML, what should be a simple thing.... I also am having trouble with the example code from post 22. Any additional advise may end my suffering! Thanks much, Brian

Avatar

Former Community Member
I did exactly what you did.

Borwser is loading with the appropriate PDF but not with the values.

Could you please send working copy to me.

Thanks again.

Avatar

Former Community Member
I am hoping to figure this one out eventually. I wish they had an example that walked you through whole process.<br /><br />I created the following code. My form appears without the field being populated also. I went into designer pull up the pdf added some data and tried to export the data as xml and xdp. The xml shows with no data. Tried to open xdp its say unable to locate template. <br /><br />Is this xml correct? (this is being used in designer to perform the <br />binding <br /><?xml version="1.0" encoding="UTF-8"?> <br /><TextField1><value>Howard</value></TextField1> <br /><br />After I have binded the field <br /><br />I use the following asp to display the pdf with <br />the one field filled in. <br /><br />Is this xml correct? <br /><br /><% Response.ContentType = "application/vnd.adobe.xdp+xml" response.write "<?xml version='1.0' encoding='UTF-8'?>" <br />response.write "<?xfa generator='AdobeDesigner_V7.0' APIVersion='2.2.4333.0'?>" <br />response.write "<xdp:xdp xmlns:xdp='http://ns.adobe.com/xdp/'>" <br />response.write "<xfa:datasets xmlns:xfa='http://www.xfa.org/schema/xfa-data/1.0/'>" <br />response.write "<xfa:data xfa:dataNode='dataGroup'>" <br />response.write "<TextField1><value>Howard</value></TextField1>" <br />response.write "</xfa:data>" <br />response.write "</xfa:datasets>" <br />response.write "<pdf href='http://159.83.96.138/prod/myFirstShot.pdf' xmlns='http://ns.adobe.com/xdp/pdf/' />" <br />response.write "<xfdf xmlns='http://ns.adobe.com/xfdf/' xml:space='preserve'>" <br />response.write "<annots/>" <br />response.write "</xfdf>" <br />response.write "</xdp:xdp>" <br />Response.Flush <br />Response.End <br /><br />%>

Avatar

Former Community Member
Garth,

In step 2 of your resolution, you mentioned to use data binding feature.

I want to know... is it (the data connection part) to be done just for testing purpose or whether it has any significance in actually generating dynamic PDF.



I am asking this question, 'cause in my case, I do not have separate XML data file. I am creating XML name value pairs in code and included that in XDP code.



Another question. What should be the "Return Method" be set to, when creating PDF form.

Fill then Submit (OR) Fill the Submit/Print (OR) Fill then Print (OR) Print



My requirement is same as yours except for XML data file which I mentioned above.



Any pointers would be of great help.



Thanks

Avatar

Former Community Member
This has been an EXTREMELY helpful thread. I was able to get this concept working. Does anyone know if its possible to force this file to save as a PDF rather than prompting the user to open or save?

Avatar

Former Community Member
I should have included in my message that I understand that it could not automatically save on the client (as this would be a big security no-no) -- I'm looking to then save it on the server.

Avatar

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

Avatar

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

Avatar

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

Avatar

Level 6
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

Avatar

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

Avatar

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

Avatar

Former Community Member
What should be specified if not Designer? Can you provide the the xfa:generate tag should look like?

Avatar

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