Expand my Community achievements bar.

Populate Livecycle PDF from mySQL database using PHP

Avatar

Former Community Member
I'm trying to set up a database of loan agreements, where users will submit a form through Acrobat and their information will be stored in a mySQL database. Later, they can go back and download the PDF, which will be repopulated with their data in the mySQL db.



I made the form in Livecycle Designer and submit the information through HTTP POST. I can easily get the information from the form into the database...my only problem is getting that information back out into the PDF.



What would allow me to write back to the PDF, preferably using PHP? What kind of syntax would that require?



Thanks!
28 Replies

Avatar

Former Community Member
For clarification...



I'm hoping to store the empty pdf on the server, so when they go back to download the "original" pdf, it's really just a recreated version of it.

Avatar

Former Community Member
I don't know a solution to your problem but I'm looking for the same answer you're seeking. However, can you tell me how you were able to setup you're pdf's to work through HTTP POST. Any help will be appreciated.

Avatar

Former Community Member
I actually just got this to work yesterday using ideas from http://www.mactech.com/articles/mactech/Vol.20/20.11/FillOnlinePDFFormsUsingHTML/index.html

I used fdftk from http://www.accesspdf.com/pdftk/ and was able to repost the data in a flattened version of my PDF form. Pretty cool.

Anyway, to get the pdf to output the form data to HTTP POST, you have to use an HTTP submit button in LiveCycle. You then have to set it to submit to a site that you create that will process the POST information. For my purposes, I created a submit.php file that took the POST info and inserted it into a mySQL database.

If you need details on how to get the HTTP POST fields to work, let me know and I'll explain better.

Avatar

Former Community Member
Any information you provide is helpful. I took a look at that example and it's cool. I was hoping that it would look similar to the form that the user would fill out and then be able to submit to a database and then print out the exact form. Having a lookup or search feature through the web would be ideal.



For now this is the best option. Thank you very much!

Avatar

Former Community Member
I actually did pretty much exactly what you wanted--submitting data from a PDF through HTTP POST and repopulating a blank form with that data later from a web lookup system.



I just wrote up a tutorial on how to do it (hopefully it's relatively complete and makes sense). Visit http://www.andrewheiss.com/Tutorials to see it.



If you have any questions, ask and I'll try to clarify the tutorial.

Avatar

Former Community Member
Is there anyway the PHP entries can look similar to the form? I didn't like that whole just straight down look and the field names are complexed. Employees may get confused looking at a complexed table on the web.



I wish there was a way to publish the already designed form to the web and have it submit to a SQL server, MySQL or even Access. This actually wasn't that hard to do with Microsoft's Infopath but I hated their controls.

Avatar

Former Community Member
The example I gave is completely barebones and purposely ugly. I haven't finished styling and designing it all yet--it was all done in a complex table so I could see all the data that was getting submitted. In the real version, the table is simpler and sortable and customizable and will be a lot less confusing.



It's purpose was to show one way to implement it, using arbitrary form field names. It's totally customizable.



Unfortunately, for the fdftk to work correctly, you have to use the long and complex field names because of how Designer structures the PDFs. If you used Acrobat to make the form fields, I believe the form names could be simpler, but I'm not sure.



The fdftk's only purpose for this application is the recreation of the PDF from submitted data. This example takes information submitted from an already designed form on the web and inserts it into a MySQL database--the only purpose of the table in my example was to show that the data actually gets in the server and can be reused for other things, like fdftk.



So, this should work for taking data and submitting it to a database.

Avatar

Former Community Member
Bobby, did you get things working?



And Andrew

I spent a good bit of time following your tutorial, I used LiveCycle Designer 8.0



everything went fine.. until the end, when i went to retrieve the PDF by clicking the link in viewpdf.php... and i cannot open the pdf, bc i get a warning that it is an unsupported format, corrupted or didnt decode properly, and when i open the PDF in Notepad its completely blank..



ive spent a couple days on this so far, and would love a little direction, b/c i believe there is just one thing missing.



you said that you got fdftk from http://www.accesspdf.com/pdftk/.



are you sure you don't mean pdftk? b/c that seems to be the only thing i can find there.



And your viewpdf.php link is dead too, i had to guess it from the others..



i would GREATLY appreciate a little direction.



chris

chris@ecoastcomputer.com

Avatar

Former Community Member
Oops. Thanks for pointing out the fdftk typo - it really is pdftk - and the dead link. It actually wasn't dead...it was linking to my .htaccess file...that's kind of dangerous! It's all fixed now...



As for the blank and corrupted PDF file at the end...I haven't run across that. I have no idea what could be going wrong. So, I zipped up and uploaded a working copy of it. You just need to make a MySQL database and change the information in config_users.php to get it to work for you.



Hopefully the full code will better explain what's going on and will show us what's wrong in my tutorial. If anyone finds where I messed up, let me know and I'll change the tutorial



The link to download it is at the beginning of the tutorial, at http://www.andrewheiss.com/Tutorials

Avatar

Former Community Member
Andrew



your link isnt working correctly, simply clicking it takes me to an un-styled xml file and d-loading it gives me nothing..



yes, that would be great to see the whoel working package and all the files invloved.. to where i could just put them on my server create the MySQL Database and see it working on my site then i know i can alter what i need to to conform for my use.



thank you for your time it is appreciated.



my email is chris@ecoastcomputer.com if you decide to email it to me..

Avatar

Former Community Member
Andrew,



I know this topic is old, but I am having trouble getting past inserting my data into the mySQL database from the PDF form. I have used your scripts and modified them with my information. I get "Successful" when I submit to the insert file, but nothing goes into the database. I even tried to use echo to set what's in the variable, and they are all blank. Any ideas why? I can send you my scripts if you would like.



-willy

Avatar

Former Community Member
Always read stuff that will make you look good if you die in the middle of it.


mp3

Avatar

Former Community Member
I have a vital form that clients fill out, which is passed to many people in the company along the workflow. The form is a Planner and we have in the following PDF, Word Doc..



Well before, the Planner.pdf was originally created in Word, since most people have access to Word.. but evolved to a PDF form created from the Word Doc via Adobe LiveCycle Designer 8.0 w/ User Rights enabled so that the form could be filled out and saved using Adobe Reader.. which was a step better than Word.. being that it is free. But this needed to be easier and more to the point b/c some clients don't particularly like installing the latest version of Reader, even if you provide them the link. Nor do they like saving the form, filling the form, and attaching the form to send back.



My goal is to have the client fill an HTML version of the form, submit and be done with it, but everyone in the workflow be able to easily receive the filled Planner as a PDF form.



So some months ago I ran into this post Chris Trip, "Populate Livecycle PDF from mySQL database using PHP" #8, 22 Sep 2007 4:37 pm



which uses the command line Win32 pdftk.exe to merge an FDF file into an existing PDF on the remote server, and serve this to whoever.



My problem was with shared hosting and having the ability to use the Win32 pdftk.exe along with PHP which is predominantly used on Linux boxes. And we used a Linux box.



so i created the following unorthodox method, which a client fills the HTML version of the Planner, all field values are INSERTED into a table in MySQL DB, I and all filled planners that have been filled by clients to date can be viewed from a repository page where an XML file is served up of the corresponding client, but someone would have to have Acrobat Professional, to import the form data from the XML file into a blank form.. altoughh this is simple for me.. I have the PHP file already created so that when a Planner is filled and client submits. >> the an email is sent to me with a table row from the repository of the client name, #, email, and a link to d-load the XML file,



But I also have the PHP files created so that the Planner can be sent to by email to various people in the workflow with certain fileds ommitted they they do not need to see, but instead of the XML file beiong served up i need the filled PDF Planner to be served.



I can do this locally with ease on a testing server, but I am currently trying to use another host that uses cross-platform compatibility so i can use PHP and the pdftk.exe to achieve this, as that is why I am having to serve up an XML file b/c we use a Linux server for our website, and cant execute the exe.



Now that I am testing the other server (cross-platform host), just to use them to do the PDF handling (and it's only $5 per month) I am having problems with getting READ, WRITE, EXECUTE permissions..



Si guess a good question to ask is can PHP do the same procedure as the pdftk.exe, and i can eleminate it.



or how in the heck can i get this data from the DB into a blank PDF form, like i have described??



here are some link to reference



Populating a LiveCycle PDF with PHP and MySQL

http://www.andrewheiss.com/Tutorials?page=LiveCycle_PDFs_and_MySQL



HTML form that passed data into a PDF

http://www.mactech.com/articles/mactech/Vol.20/20.11/FillOnlinePDFFormsUsingHTML/index.html

and an example

http://accesspdf.com/html_pdf_form/

________________________________________

Avatar

Former Community Member
I recently found Andrew Heiss's Tutorial on PDF form to MySQL Database. I have Acrobat 8.0 w/ Livecycle, MySQL, & the insert.php file setup. I am not having any trouble getting data from the form to the database... except that when the data comes from the .pdf form it takes all the fields and puts the data from those fields into the first column only "FirstName" of the database. I think that the data is being combined on the form before being sent to the .php file because when I put a value into the variables on the .php page it organizes everything right.



Anyone have an idea why the fields combine together when being submitted and how to keep that from happening?

Avatar

Former Community Member
Hello Chris,



I am also facing the same problem that you have faced. So, Have you got any idea for solving that problem? I have spent couple of days for solving that problem. But I did not find out the solution.



The problem is I have facing problem for showing data in pdf form. During the time of opening the pdf file It shows the message that file is corrupted or damaged.



Please help me......



Thank you

Saroj neupane

Avatar

Former Community Member
This is great and exactly what we need - does the PDF then get mailed to our e-mail automatically?

Avatar

Former Community Member
@bpittam - It can e-mail the PDF if you want, although the idea of the system is to reduce the amount of large files that need to be moved around, hence the MySQL database. You would just need to modify the code to use the PHP mail() function.



There's actually a better updated version of this script at http://code.google.com/p/pdftk-php/ - it works a lot better and more consistently.

Avatar

Former Community Member
Andrew - I am trying to get this form to work:



http://www.brandonpittam.com/senior_model_application.pdf



I tried your tutorial, but I think I just need to keep looking at your tutorial more. But if you have any suggestions to how this might work, I am all ears. Thanks



Brandon