Posts: 409
Name: Harry Burt
Location: Colchester, Essex, England
|
Yeah, I would agree that it's quite difficult, but it can be done. I generate PDF invoices that include right aligning like this:
PHP Code:
<?php function gety($suspect){ return 842 - $suspect; } function parse_pence($pence){ if($pence == 0)return "£0.00"; $pence = "£".($pence/100); if(strlen($pence) == 2)$pence = $pence.".00"; return $pence; } if($_POST){ $runningtotal = 0; $items = 1; $totalitems = 0; $pdf = pdf_new(); $ident = $_POST['ident']; $dear = $_POST['dear']; $path = $ident.".pdf"; $months = $_POST['months']; $hours = $_POST['hours']; $webcost = $_POST['cost']; $extras = $_POST['extras']; $extrascost = $_POST['extrascost']; $servicecost = $_POST['servicecost']; $usewebdesign = $_POST['webdesignselect']; $useextras = $_POST['extrasselect']; $useservices = $_POST['serviceselect']; $usecustom = $_POST['customselect']; $customline= $_POST['customline']; $customprice = $_POST['customprice']; if($usewebdesign) $totalitems++; if($useextras) $totalitems++; if($useservices) $totalitems++; if($usecustom) $totalitems++; pdf_open_file($pdf, $path); $font = pdf_load_font($pdf, "Helvetica-Bold", "host", ""); $fontid = pdf_findfont($pdf, 'Helvetica-Bold', 'host', 0); pdf_begin_page($pdf, 595, 842); pdf_setfont($pdf,$font,14); pdf_moveto($pdf, 28, gety(280)); pdf_lineto($pdf, 564, gety(280)); pdf_moveto($pdf, 438, gety(260)); pdf_lineto($pdf, 438, gety((330 + (35 * $totalitems)))); pdf_moveto($pdf, 28, gety((305 + (35 * $totalitems)))); pdf_lineto($pdf, 564, gety((305 + (35 * $totalitems)))); pdf_moveto($pdf, 28, gety((330 + (35 * $totalitems)))); pdf_lineto($pdf, 564, gety((330 + (35 * $totalitems)))); pdf_stroke($pdf); $logo = pdf_load_image($pdf, "jpeg", "flogo.jpg", ""); pdf_fit_image($pdf, $logo, 28, gety(140),""); $signharry = pdf_load_image($pdf, "jpeg", "harrysign.jpg", ""); pdf_fit_image($pdf, $signharry, 28, gety((535 + (35 * $totalitems))),"scale 1.5"); $signleon = pdf_load_image($pdf, "jpeg", "leonsign.jpg", ""); pdf_fit_image($pdf, $signleon, 200, gety((530 + (35 * $totalitems))),"scale 1.5"); pdf_show_xy($pdf,"Foundation Flash", (564 - pdf_stringwidth($pdf,"Foundation Flash",$fontid,14)), gety(46)); pdf_show_xy($pdf,"Email: foundationflash@gmail.com", (564 - pdf_stringwidth($pdf,"Email: foundationflash@gmail.com",$fontid,14)), gety(61)); pdf_show_xy($pdf,"Springbank House,", (564 - pdf_stringwidth($pdf,"Springbank House,",$fontid,14)), gety(81)); pdf_show_xy($pdf,"Spring Gardens Road,", (564 - pdf_stringwidth($pdf,"Spring Gardens Road,",$fontid,14)), gety(96)); pdf_show_xy($pdf,"Chappel,", (564 - pdf_stringwidth($pdf,"Chappel,",$fontid,14)), gety(111)); pdf_show_xy($pdf,"Colchester,", (564 - pdf_stringwidth($pdf,"Colchester,",$fontid,14)), gety(126)); pdf_show_xy($pdf,"CO6 2DN", (564 - pdf_stringwidth($pdf,"CO6 2DN",$fontid,14)), gety(141)); pdf_show_xy($pdf,date("jS F Y"), (564 - pdf_stringwidth($pdf,date("jS F Y"),$fontid,14)), gety(160)); pdf_setfont($pdf,$font,16); pdf_show_xy($pdf,"Dear $dear", 28, gety(200)); pdf_show_xy($pdf,"Below is a list of the services rendered, and a breakdown of costs. The", 28, gety(220)); pdf_show_xy($pdf,"total amount due is listed in the Total: box.", 28, gety(240)); pdf_setfont($pdf,$font,14); pdf_show_xy($pdf,"Description of Service/Product Provided", 28, gety(275)); pdf_show_xy($pdf,"Sub-Total", 445, gety(275)); if($usewebdesign){ pdf_show_xy($pdf,"Website design, totalling $hours hours", (433 - pdf_stringwidth($pdf,"Website design, totalling $hours hours",$fontid,14)), gety((275 + (35 * $items)))); pdf_show_xy($pdf,parse_pence($webcost), 444, gety((275 + (35 * $items)))); $runningtotal += $webcost; $items++; } if($usecustom){ pdf_show_xy($pdf,"$customline", (433 - pdf_stringwidth($pdf,"$customline",$fontid,14)), gety((275 + (35 * $items)))); pdf_show_xy($pdf,parse_pence($customprice), 444, gety((275 + (35 * $items)))); $runningtotal += $customprice; $items++; } if($useextras){ pdf_show_xy($pdf,"Extra resources required - $extras", (433 - pdf_stringwidth($pdf,"Extra resources required - $extras",$fontid,14)), gety((275 + (35 * $items)))); pdf_show_xy($pdf,parse_pence($extrascost), 444, gety((275 + (35 * $items)))); $runningtotal += $extrascost; $items++; } if($useservices){ pdf_show_xy($pdf,"Service included ($months months)", (433 - pdf_stringwidth($pdf,"Service included ($months months)",$fontid,14)), gety((275 + (35 * $items)))); pdf_show_xy($pdf,parse_pence($servicecost), 444, gety((275 + (35 * $items)))); $runningtotal += $servicecost; $items++; } pdf_show_xy($pdf,"Total:", (433 - pdf_stringwidth($pdf,"Total:",$fontid,14)), gety((325 + (35 * $totalitems)))); pdf_show_xy($pdf,parse_pence($runningtotal), 444, gety((325 + (35 * $totalitems)))); pdf_setfont($pdf,$font,16); pdf_show_xy($pdf,"Please don't hesitate to contact us if you have any queries. Payment can", 28, gety((365 + (35 * $totalitems)))); pdf_show_xy($pdf,"most easily be made by clicking the \"Make a Donation\" box on the right", 28, gety((385 + (35 * $totalitems)))); pdf_show_xy($pdf,"hand side of www.foundation-flash.com.", 28, gety((405 + (35 * $totalitems)))); pdf_show_xy($pdf,"Yours sincerely,", 28, gety((455 + (35 * $totalitems)))); pdf_show_xy($pdf,"Harry Burt and Leon Aves", 28, gety((550 + (35 * $totalitems)))); pdf_end_page($pdf); pdf_close($pdf); pdf_delete($pdf); } ?>
That's a complete mess of course, but it works perfectly.
|