Reply
PDF Invoice
Old 11-03-2007, 07:37 AM PDF Invoice
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
I have to make a script that saves an Invoice in PDF format.
The way i did it so far is to make a PDF Template with fields like {*BUYER_NAME*} in it and str_replace them.

The problem that i have is when the names of the buyer, or products are too long. How do i make the string to spilt into another row. And how do i make the text below it to go even lower.

Does anybody have a diferent method of doing this ? Maybe Much Better.

The other thing that i was thinking is to make the whole invoice from scratch in PDF.

Thank you
__________________
If you like my posts ... TK is appreciated:)
Web Directory | Blog
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
When You Register, These Ads Go Away!
Old 11-03-2007, 10:25 AM Re: PDF Invoice
tripy's Avatar
Fetchez la vache!

Posts: 2,054
Name: Thierry
Location: In the void
If you run the site on a vps or dedicated server, you should look to FOP ( http://xmlgraphics.apache.org/fop/ ).
It's a java command line software that allows you to create a PDF dynamically by providing datas (in a XML file) and formating (via an XSL-FO stylesheet) to generate the PDF.
The XSL stylesheet is not really different from HTML, and this could be far more effective than replacing strings in a already generated PDF.

http://www.w3schools.com/xslfo/default.asp
http://www.renderx.com/tutorial.html
http://www.ecrion.com/Support/Resour...XSLFO.xml.html
__________________
Listen to the ducky: "This is awesome!!!"

tripy is offline
Reply With Quote
View Public Profile
 
Old 11-03-2007, 10:30 AM Re: PDF Invoice
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
thank you for you're answer, but i don't have a VPS

any other ideeas ?
__________________
If you like my posts ... TK is appreciated:)
Web Directory | Blog
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 11-03-2007, 02:28 PM Re: PDF Invoice
Foundationflash's Avatar
Ultra Talker

Posts: 409
Name: Harry Burt
Location: Colchester, Essex, England
PHP can generate PDFs by itself using a custom .dll.
__________________
Foundation Flash tutorials : www.foundation-flash.com

New Dreamed Up Web Design: www.dreamedupdesign.com
Foundationflash is offline
Reply With Quote
View Public Profile Visit Foundationflash's homepage!
 
Old 11-03-2007, 04:10 PM Re: PDF Invoice
tripy's Avatar
Fetchez la vache!

Posts: 2,054
Name: Thierry
Location: In the void
Quote:
Originally Posted by Foundationflash View Post
PHP can generate PDFs by itself using a custom .dll.
True, but what an head crusher when you need to do something a little bit complicated....
I don't remember what lib I was using, but take a look on http://www.fpdf.org/ , they seems to be pretty widely used, and surely you could find resources for it.
__________________
Listen to the ducky: "This is awesome!!!"

tripy is offline
Reply With Quote
View Public Profile
 
Old 11-04-2007, 07:14 AM Re: PDF Invoice
Foundationflash's Avatar
Ultra Talker

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($pdf595842);
pdf_setfont($pdf,$font,14);
pdf_moveto($pdf28gety(280));
pdf_lineto($pdf564gety(280));
pdf_moveto($pdf438gety(260));
pdf_lineto($pdf438gety((330 + (35 $totalitems))));
pdf_moveto($pdf28gety((305 + (35 $totalitems))));
pdf_lineto($pdf564gety((305 + (35 $totalitems))));
pdf_moveto($pdf28gety((330 + (35 $totalitems))));
pdf_lineto($pdf564gety((330 + (35 $totalitems))));
pdf_stroke($pdf);
$logo pdf_load_image($pdf"jpeg""flogo.jpg""");
pdf_fit_image($pdf$logo28gety(140),"");
$signharry pdf_load_image($pdf"jpeg""harrysign.jpg""");
pdf_fit_image($pdf$signharry28gety((535 + (35 $totalitems))),"scale 1.5");
$signleon pdf_load_image($pdf"jpeg""leonsign.jpg""");
pdf_fit_image($pdf$signleon200gety((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"28gety(200));
pdf_show_xy($pdf,"Below is a list of the services rendered, and a breakdown of costs. The"28gety(220));
pdf_show_xy($pdf,"total amount due is listed in the Total: box."28gety(240));
pdf_setfont($pdf,$font,14);
pdf_show_xy($pdf,"Description of Service/Product Provided"28gety(275));
pdf_show_xy($pdf,"Sub-Total"445gety(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), 444gety((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), 444gety((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), 444gety((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), 444gety((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"28gety((365 + (35 $totalitems))));
pdf_show_xy($pdf,"most easily be made by clicking the \"Make a Donation\" box on the right"28gety((385 + (35 $totalitems))));
pdf_show_xy($pdf,"hand side of www.foundation-flash.com."28gety((405 + (35 $totalitems))));
pdf_show_xy($pdf,"Yours sincerely,"28gety((455 + (35 $totalitems))));
pdf_show_xy($pdf,"Harry Burt and Leon Aves"28gety((550 + (35 $totalitems))));
pdf_end_page($pdf);
pdf_close($pdf);
pdf_delete($pdf);
}
?>
That's a complete mess of course, but it works perfectly.
__________________
Foundation Flash tutorials : www.foundation-flash.com

New Dreamed Up Web Design: www.dreamedupdesign.com
Foundationflash is offline
Reply With Quote
View Public Profile Visit Foundationflash's homepage!
 
Reply     « Reply to PDF Invoice
 

Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.15594 seconds with 12 queries