These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Fill form fields with PhP

tvdsluijs
Registered: Jan 3 2010
Posts: 2

Hi,

I have created a php/html form. I would like to fill a existing PDF (livecycle created dynamic) from with the form fields.

I would like it to be a web display or a downloadeble form.

Workflow,

User opens a Web Form and types in his name, address eg.
User clicks submit button

Browser opens a new page with the filled in PDF form
or
Browser downloads a filled in PDF form

I cannot install any extra php addons on the server.

This is installed on the server:
PDF Support enabled
PDFlib GmbH Version 7.0.4p4
PECL Version 2.1.6
Revision $Revision: 1.9 $

I don't want to recreate the whole document as it is a 10 page document with lots of predefined text and images.

Thank you.

My Product Information:
Acrobat Standard 9.2, Unix/Linux
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I haven't tried this with a LiveCycle form, but there is a methodology that works great with regular AcroForms. There are a number of options that can be appended to a link to a PDF document. Go to the http://www.adobe.com/devnet site and search for the PDFOpenParameters.pdf file. It's the spec. One of these options is for loading an FDF file, i.e. prefilling the form when it loads on the client side. The idea is that you're PHP script generates an FDF file, places it in a server folder, and then returns HTML to the client with a modified link to the PDF and the FDF file. When the user clicks on the link the browser passes the URL to Acrobat, which loads the PDF and prefills the form with the FDF data.

Unfortunately LiveCycle (XFA) files don't really get along with FDF. They require an XML format, the gramar depends on how you've setup your form. But there are several different ways to get around this problem.

1. An XDP package, i.e., an XML file in the LiveCycle XFA Data Package gramar, can include an embedded form. When Acrobat loads the XDP it will automatically open the embedded form and populate it with the data in the XDP datasets section. You can see what this looks like by exporting an XDP package from Acrobat Pro that includes both the form data and the embedded form. So the idea here is to have a basice XDP file on the server. The PHP script modifies the datasets section of the XDP with the data on the HTML form and returns a link to the modified XDP to the client. Since this is all XML you already have the tools you need in PHP to modify the XDP.

2. Create a simple XML file with the HTML data in it. Pass an FDF (in a link) back to the client that contains JavaScript directing the XFA form to load the XML data.

3. Create a simple XML file and pass an URL to the data in a query string format in the Link to PDF form. Then use JavaScript in the form to extract the URL and load the data. Stephan Cameron (http://forms.stefcameron.com/) has a blog entry on this topic.

4. Give up on LiveCycle and use an AcroForm with the original FDF methodology.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script