Jump to content

Adding The Php_pdf.dll To A Hosted Installation


chibineku
 Share

Recommended Posts

My newfound interest in creating .pdf files with PHP has been scuppered rather earlier than usual by the fact that the php_pdf.dll extension isn't native to php5, which is the version I am using. In fact, checking the php4 installation on my webhost, it doesn't seem the pdf extension is available from that, either. I have written asking them to include it, but if they won't, is it possible for me to add that functionality without having access to the server and the php_ini file? Before I get too carried away, the reason I want it is to dynamically create packing slips for orders, which will be formatted to fit onto A4 sheets with a label area for the delivery address. Is it easier doing this using the pdf extension or using CSS? Whatever is easier and quicker is the one I want, but I also want it to be reliable and accurate. If I can't get the pdf extension, I am stuck anyway.

Link to comment
Share on other sites

Excellent, JSG, thank you very much :) My hosting company said they will look into getting the pdflib extension enabled(DLed from PECL), but in the event that they can't it's good to know I have options. Is it easy to use? The layout I want isn't massively complex, but I do want quite precise positioning, an image, color bars and a table.

Link to comment
Share on other sites

It's pure OO...I feel so lost. I've spent a while trying the css method and it is far from ideal, mainly due to printer margin issues. I don't suppose anyone has any sample scripts of something like an order confirmation, generated from MySQL data, they could let me peek at? I haven't a clue where to start. Or, perhaps a procedural PDF library? I had a look and found nothing.

Link to comment
Share on other sites

FPDF isn't that difficult, it's OO but I was able to use it pretty early in my PHP career. The fpdf.org site has a tutorials section with a few examples there, also check through the manual on that site. The Cell method is what you'll mostly use to write the text to the page. I'm looking for examples on my computer here, if I find one I'll post it.

Link to comment
Share on other sites

Here's something from an old project for a cleaning services company which generates a proposal from data in the database:

<?phprequire_once("../../include/global.conf.php");require_once("fpdf.php");get_form_var("id");$prop_info = db_get("SELECT * FROM proposals WHERE id={$id}", __FILE__, __LINE__);$company_info = db_get("SELECT * FROM companies WHERE id={$prop_info['company']}", __FILE__, __LINE__);$doc = new PDF();$doc->AddPage();$doc->SetFont("Arial", "B", 14);$doc->SetY(144);$doc->Cell(0, 16, "PRICING SCHEDULE", 0, 1, "C");$doc->ln();$doc->Cell(0, 16, "FOR", 0, 1, "C");$doc->SetY($doc->GetY() + 36);$doc->SetFont("Arial", "", 12);$doc->Cell(0, 14, $company_info['name'], 0, 1, "C");$doc->Cell(0, 14, $company_info['address1'] . " " . $company_info['address2'], 0, 1, "C");$city = "";if ($company_info['city'] != ""){  $city .= $company_info['city'];  if ($company_info['state'] != "")  {	$city .= ", " . $company_info['state'];	if ($company_info['zip'] != "")	  $city .= " " . $company_info['zip'];  }}$doc->Cell(0, 14, $city, 0, 1, "C");$doc->ln();$doc->Cell(0, 14, "The Premises will be serviced {$prop_info['days']} day(s) per week for a", 0, 1, "C");$doc->Cell(0, 14, "monthly charge of:", 0, 1, "C");$doc->ln();$subtotals = array();$subtotals['general']['cost'] = 0;$subtotals['floor']['cost']   = 0;$subtotals['carpet']['cost']  = 0;$subtotals['other']['cost']   = 0;$result = db_query("SELECT * FROM proposal_areas WHERE proposal={$id} AND service='general'", __FILE__, __LINE__);while ($row = db_fetch_assoc($result)){  if ($row['ft_rate'] != 0 && $row['ft_rate'] != "")	$daily_hrs = $row['sqft'] / $row['ft_rate'];  else	$daily_hrs = 0;  $mo_hours = $daily_hrs * $row['freq'] * 4.33;  $subtotals['general']['cost'] += ($mo_hours * $row['hr_rate']);}if ($subtotals['general']['cost'] > 0){  $doc->Cell(160, 14, "", 0);  $doc->Cell(180, 14, "General Clean..............................", 0);  $doc->Cell(72, 14, "$" . write_number($subtotals['general']['cost']), 0, 1, "R");}$result = db_query("SELECT * FROM proposal_areas WHERE proposal={$id} AND service='floor'", __FILE__, __LINE__);while ($row = db_fetch_assoc($result)){  if ($row['area'] == "stripping" || $row['area'] == "scrubbing")  {	#whacked out special formulas for these	if ($row['ft_rate'] != 0 && $row['ft_rate'] != "")	  $yr_hours = ($row['sqft'] / $row['ft_rate']) * $row['freq'];	else	  $yr_hours = 0;	if ($yr_hours != 0)	  $mo_hours = $yr_hours / 12;	else	  $mo_hours = 0;  }  else  {	#whacked out normal formula instead	if ($row['ft_rate'] != 0)	  $mo_hours = ($row['sqft'] / $row['ft_rate']) * $row['freq'] * 4.33;	else	  $mo_hours = 0;  }  $subtotals['floor']['cost'] += ($mo_hours * $row['hr_rate']);}if ($subtotals['floor']['cost'] > 0){  $doc->Cell(160, 14, "", 0);  $doc->Cell(180, 14, "Floor Care....................................", 0);  $doc->Cell(72, 14, "$" . write_number($subtotals['floor']['cost']), 0, 1, "R");}$result = db_query("SELECT * FROM proposal_areas WHERE proposal={$id} AND service='carpet'", __FILE__, __LINE__);while ($row = db_fetch_assoc($result)){  if ($row['area'] == "extraction")  {	if ($row['ft_rate'] != 0 && $row['ft_rate'] != "")	  $yr_hours = ($row['sqft'] / $row['ft_rate']) * $row['freq'];	else	  $yr_hours = 0;	if ($yr_hours != 0)	  $mo_hours = $yr_hours / 12;	else	  $mo_hours = 0;  }  else  {	if ($row['ft_rate'] != 0)	  $daily_hrs = $row['sqft'] / $row['ft_rate'];	else	  $daily_hrs = 0;	$mo_hours = $daily_hrs * $row['freq'] * 4.33;  }  $subtotals['carpet']['cost'] += ($mo_hours * $row['hr_rate']);}if ($subtotals['carpet']['cost'] > 0){  $doc->Cell(160, 14, "", 0);  $doc->Cell(180, 14, "Carpet Care..................................", 0);  $doc->Cell(72, 14, "$" . write_number($subtotals['carpet']['cost']), 0, 1, "R");}$result = db_query("SELECT * FROM proposal_areas WHERE proposal={$id} AND service='other'", __FILE__, __LINE__);while ($row = db_fetch_assoc($result)){  $wk_hrs = $row['qty'] * $row['freq'] * $row['day_hrs'];  $mo_hours = $wk_hrs * 4.33;  $subtotals['other']['cost'] += ($mo_hours * $row['hr_rate']);}if ($subtotals['other']['cost'] > 0){  $doc->Cell(160, 14, "", 0);  $doc->Cell(180, 14, "Other Services.............................", 0);  $doc->Cell(72, 14, "$" . write_number($subtotals['other']['cost']), 0, 1, "R");}$cur_x = $doc->GetX();$cur_y = $doc->GetY();$doc->SetLineWidth(1);$doc->Line($cur_x + 346, $cur_y, $cur_x + 412, $cur_y);$doc->SetFont("Arial", "B", 12);$doc->Cell(160, 14, "", 0);$doc->Cell(180, 14, "Total Cost", 0, 0, "R");$doc->Cell(72, 14, "$" . write_number($subtotals['general']['cost'] + $subtotals['carpet']['cost'] + $subtotals['floor']['cost'] + $subtotals['other']['cost']), 0, 1, "R");$doc->ln();$doc->ln();$doc->ln();$doc->Cell(0, 14, "Square Footage To Be Cleaned: " . write_number($prop_info['sqfeet']), 0, 1, "C");$doc->Output("proposal", "I");?>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...