PHP, MySQL & PDF's
Ok, small problem here and I've been scouring the web trying to find a solution. I've found references to doing this but no real meat & potatoes answers. Anyways I have a form I created in Adobe LiveCycle, with this form I can submit and record data to a MySQL database, this works great. However the problem I am having is when it comes time to view a record I need to populate the form with the information to view/print or whatever. How do you do this? For arguments sake the reason I want to go with PDF forms over HTML is that I have quite a few forms I need to recreate and some of them are very large, it would save me a lot of time if I was able to use a pdf form over hand writing a bunch of HTML forms and then creating the view scripts in PHP/HTML and making sure they will print correctly. Hope this makes sense.
I haven't been able to find a way just using php to do this. I use coldfusion for it. If you have access to it I can show you my code.
I am unfamiliar with ColdFusion, I do know my current host hostgator.com doesn't support it but I'd be willing to change to another one if this would solve my problem, looks like hostek.com has reasonable rates.
This doesn't quite make sense to me. You would normally use PHP to construct a page which displays all the information, with the information itself being returned from the database. So, there is only one page but its data changes when the page is requested.
You could use PHP to create or modify a PDF and then forward this to the browser. The browser will normally either offer to download the pdf (and save it) or open it in an in-browser pdf-viewer.
There are a number of PHP-PDF libraries that enable you to create or modify pdfs.
The reason I want to stick to using PDF forms is just the shear amount and size of the forms I have to recreate, I could go through and recreate all of these in HTML if I have too, I would just rather not. Instead of coding out the form then making the processing scripts for viewing and posting and such I figured if possible, I could redo the forms in LiveCycle, which is pretty much just drag and drop, then save the information to the database from that form and then somehow pull the database information back out and put it in the form using php or possibly some other language. If it's not possible I will have to go this route I guess, not fun but I may have to do it.
Originally Posted by AndrewGSW
I don't know about LiveCycle but it's an Adobe product and it seems then can create PDF forms that are viewable in a browser, according to this.
A terrible hack would be to save a pdf as an image, set it as the background to a div, and use absolutely positioned form-elements to sit above it :(
If you use pdf's alot Coldfusion is an Adobe product and has some great interactivity in creating pdfs
<cfparam name="URL.access" default="0">
<cfquery name="get_admin" datasource="#request.dsn#">
SELECT * FROM admin WHERE uuid = '#URL.access#' LIMIT 1
<cfpdfform source="YOUR-URL\www\purchase_contract.pdf" action="populate" destination="#session.document_root#\#URL.access#.pdf" overwrite="yes">
<cfpdfformparam name="admin" value="#get_admin.first_name# #get_admin.last_name#">
<cfpdfformparam name="admin_email" value="#get_admin.email#">
<!--- This flattens the file and shows it with no editable fields. Dont use this if you want them to be able to change.--->
<cfpdf action="write" destination="#session.document_root#\#URL.access#" source="#session.document_root#\#URL.access#.pdf" flatten="yes" overwrite="yes">
<cfheader name="Content-Disposition" value="inline; filename=#session.document_root#\#URL.access#">
<cfcontent file="#session.document_root#\#URL.access#" type="application/pdf" >
The easiest way to create PDFs from PHP is to use FPDF.
I have looked at that felgall but I couldn't find any way to populate a pdf form. Do you know if they have a way to do that? I have some clients that are strictly php.
Actually I think I just found it. I have not tried this and just found it on the internet. On this site http://fpdf.org/ in the examples
Sample using a PHP array
$fields = array(
'name' => 'My name',
'address' => 'My address',
'city' => 'My city',
'phone' => 'My phone number'
$pdf = new FPDM('template.pdf');
$pdf->Load($fields, false); // second parameter: false if field values are in ISO-8859-1, true if UTF-8