Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-19-2013, 07:05 PM   PM User | #1
dustywb
New Coder

 
Join Date: Nov 2004
Posts: 55
Thanks: 8
Thanked 2 Times in 1 Post
dustywb is an unknown quantity at this point
Exclamation 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.

Thanks!
dustywb is offline   Reply With Quote
Old 01-19-2013, 07:19 PM   PM User | #2
jimhill
Regular Coder

 
Join Date: Jul 2010
Posts: 271
Thanks: 3
Thanked 40 Times in 40 Posts
jimhill is an unknown quantity at this point
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.
__________________
If you can't stand behind your troops, feel free to stand in front of them
Semper Fidelis
jimhill is offline   Reply With Quote
Old 01-19-2013, 07:26 PM   PM User | #3
dustywb
New Coder

 
Join Date: Nov 2004
Posts: 55
Thanks: 8
Thanked 2 Times in 1 Post
dustywb is an unknown quantity at this point
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.
dustywb is offline   Reply With Quote
Old 01-19-2013, 07:28 PM   PM User | #4
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 01-19-2013, 07:39 PM   PM User | #5
dustywb
New Coder

 
Join Date: Nov 2004
Posts: 55
Thanks: 8
Thanked 2 Times in 1 Post
dustywb is an unknown quantity at this point
Quote:
Originally Posted by AndrewGSW View Post
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.
dustywb is offline   Reply With Quote
Old 01-19-2013, 07:46 PM   PM User | #6
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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
Attached Thumbnails
Click image for larger version

Name:	adobepdf.jpg
Views:	23
Size:	34.4 KB
ID:	11871  
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS

Last edited by AndrewGSW; 01-19-2013 at 07:49 PM..
AndrewGSW is offline   Reply With Quote
Old 01-19-2013, 07:49 PM   PM User | #7
jimhill
Regular Coder

 
Join Date: Jul 2010
Posts: 271
Thanks: 3
Thanked 40 Times in 40 Posts
jimhill is an unknown quantity at this point
If you use pdf's alot Coldfusion is an Adobe product and has some great interactivity in creating pdfs
Code:
<cfparam name="URL.access" default="0">
<cfquery name="get_admin" datasource="#request.dsn#">
SELECT * FROM admin WHERE uuid = '#URL.access#' LIMIT 1
</cfquery>

<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#"> 
</cfpdfform>
<!--- 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" >
__________________
If you can't stand behind your troops, feel free to stand in front of them
Semper Fidelis
jimhill is offline   Reply With Quote
Old 01-19-2013, 09:31 PM   PM User | #8
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,452
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
The easiest way to create PDFs from PHP is to use FPDF.

http://fpdf.org/
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 01-19-2013, 09:43 PM   PM User | #9
jimhill
Regular Coder

 
Join Date: Jul 2010
Posts: 271
Thanks: 3
Thanked 40 Times in 40 Posts
jimhill is an unknown quantity at this point
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.
__________________
If you can't stand behind your troops, feel free to stand in front of them
Semper Fidelis
jimhill is offline   Reply With Quote
Old 01-19-2013, 09:48 PM   PM User | #10
jimhill
Regular Coder

 
Join Date: Jul 2010
Posts: 271
Thanks: 3
Thanked 40 Times in 40 Posts
jimhill is an unknown quantity at this point
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

PHP Code:
<?php

/***************************
  Sample using a PHP array
****************************/

require('fpdm.php');

$fields = array(
    
'name'    => 'My name',
    
'address' => 'My address',
    
'city'    => 'My city',
    
'phone'   => 'My phone number'
);

$pdf = new FPDM('template.pdf');
$pdf->Load($fieldsfalse); // second parameter: false if field values are in ISO-8859-1, true if UTF-8
$pdf->Merge();
$pdf->Output();
?>
__________________
If you can't stand behind your troops, feel free to stand in front of them
Semper Fidelis
jimhill is offline   Reply With Quote
Reply

Bookmarks

Tags
forms, mysql, pdf, php, populate

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:29 PM.


Advertisement
Log in to turn off these ads.