PDA

View Full Version : html2pdf?


Vee
24-06-2009, 12:07 PM
Hi peeps,

html2pdf in PHP - what are the cool kids using these days?

Cheers

Vee
26-06-2009, 08:58 AM
Nobody has done html2pdf with PHP lately?

I bet it's one line in RoR :rolleyes:

kay
26-06-2009, 09:24 AM
Nobody has done html2pdf with PHP lately?

I bet it's one line in RoR :rolleyes:

This is it in ColdFusion:


<cfdocument format="PDF">
<h1>UR HTML GOES HERE</h1>
</cfdocument>


;)

madpilot
26-06-2009, 11:26 AM
Nobody has done html2pdf with PHP lately?

I bet it's one line in RoR :rolleyes:

Nah, not quite (Although I haven't look at prawn yet, which is supposed to be wikid.)

Have a look at tcpdf for PHP - it has a basic HTML parser.

Franki
26-06-2009, 11:47 AM
<?
require('html2fpdf.php');
$pdf=new HTML2FPDF();
$pdf->AddPage();
$fp = fopen("sample.html","r");
$strContent = fread($fp, filesize("sample.html"));
fclose($fp);
$pdf->WriteHTML($strContent);
$pdf->Output("sample.pdf");
echo "PDF file is generated successfully!";
?>

Vee
26-06-2009, 03:28 PM
Thanks, I'll look into them both.

benmay
29-06-2009, 01:55 PM
I use domfpdf which is now on google code, and for CodeIgniter - handles MOST css elements, some things you need to gear it back to basic HTML, but very nice otherwise

stevebramley
29-06-2009, 04:58 PM
I did a bunch of html2pdf for a client year before last, autogenerating reciepts for online payments. what you after? I'd be happy to dig it up and pass it on if it's suitable.

Vee
29-06-2009, 05:05 PM
This should be fairly straightforward - it's an online application form that needs to be delivered to the client by email in a ready to print format for offline processing and storage.

Their current system has the client downloading an ever increasing CSV file before manually performing a mail merge on the latest entries. It takes the client a whole couple of minutes but it's just a lame way of doing things.

The project hasn't started yet but I'd love to see some existing code, if only to get an idea of another way of doing things. I'll PM you my email address, Steve.

patricktt
29-06-2009, 05:35 PM
I have used dompdf quite a bit and recommend it, it's very easy to use and the results are impressive :)

stevebramley
30-06-2009, 08:35 AM
Vee,

//grab the free pdf app: http://www.fpdf.org/

require('/includes/fpdf153/fpdf.php');

//extend it with your page settings etc
//---------- begin pdf ----------------
class PDF extends FPDF{

var $unique_id = "";
var $company_name = "";
var $abn = "";
var $address1 = "";
var $address2 = "";
var $country = "";
var $email = "";
var $web = "";
var $phone = "";
var $fax = "";
var $bank = "";
var $account_name = "";
var $bsb = "";
var $account_number = "";
var $item = "";
var $description = "";
var $amount = "";

//Page header
function init($row=NULL){
$this->unique_id = str_pad($row->unique_id,5,0,STR_PAD_LEFT);
$this->company_name = $row->company_name;
$this->abn = $row->abn;
$this->address1 = $row->address1;
$this->address2 = $row->address2;
$this->country = $row->state;
$this->email = $row->email;
$this->web = $row->web;
$this->phone = $row->phone;
$this->fax = $row->fax;
$this->bank = $row->bank;
$this->account_name = $row->account_name;
$this->bsb = $row->bsb;
$this->account_number = $row->account_number;
$this->item = $row->item;
$this->description = $row->description;
$this->amount = number_format($row->amount,2);
$this->gst = number_format(($this->amount/11),2);
}
//Page header
function Header(){
//Logo
$this->Image('/images/pdf/logo.jpg',10,8,33);
//Arial bold 15
$this->SetFont('Arial','B',15);
//Move to the right
$this->Cell(140);
//Title
$this->Cell(40,10,'Tax Invoice',0,0,'R');
//Arial normal 10
$this->SetFont('Arial','',10);
//Line break
$this->Ln(20);
//Address
$this->Cell(40,10,$this->company_name,0,0,'L');
//Line break
$this->Ln(5);
//Address
$this->Cell(40,10,$this->address1,0,0,'L');
//Line break
$this->Ln(5);
//Address
$this->Cell(40,10,$this->address2,0,0,'L');

//Move to the right
$this->Cell(60);
$this->SetFont('Arial','',7);
$this->SetFillColor(250,250,250);
//Title
$this->Cell(35,5,'TAX REG No.',1,0,'L','1');
//Title
$this->Cell(25,5,'DATE',1,0,'L','1');
//Title
$this->Cell(35,5,'INVOICE No.',1,0,'L','1');

$this->SetFont('Arial','',10);
//Line break
$this->Ln(5);
//Address
$this->Cell(40,10,$this->country,0,0,'L');

//Move to the right
$this->Cell(60);
//Title
$this->Cell(35,8,$this->abn,1,0,'L','0');
//Title
$this->Cell(25,8,date("d/m/Y"),1,0,'L','0');
//Title
$this->Cell(35,8,$this->unique_id,1,0,'L','0');

//Line break
$this->Ln(10);
//Address
$this->Cell(40,10,"Email: " . $this->email,0,0,'L');
//Line break
$this->Ln(5);
//Address
$this->Cell(40,10,"Web: " . $this->web,0,0,'L');
}
}
//instatiate it and create your pdf page
$pdf=new PDF();
$pdf->init($invoice_row);
$pdf->AddPage();
$pdf->Ln(15);
$pdf->SetFillColor(250,250,250);
$pdf->SetFont('Arial','',6);
$pdf->Cell(80,5,"INVOICE TO",1,0,'L','1');
$pdf->Cell(20,5);
$pdf->Cell(60,9,"TERMS",1,0,'C','1');
$pdf->Cell(35,9,"DUE DATE",1,0,'C','1');
$pdf->Ln(5);
$pdf->SetFont('Arial','',8);
$pdf->Cell(80,5,$name,"LR",0,'L','0');
$pdf->Ln(4);
$pdf->Cell(80,5,$company_name,"LR",0,'L','0');
$pdf->Cell(20,5);
$pdf->Cell(60,5,"Payment Immediate",1,0,'C','0');
$pdf->Cell(35,5,date("d/m/Y"),1,0,'C','0');
$pdf->Ln(5);
$pdf->Cell(80,5,$address1,"LR",0,'L','0');
$pdf->Ln(4);
$pdf->Cell(80,5,$suburb . ", " . $postcode,"LR",0,'L','0');
$pdf->Cell(20,5);
$pdf->SetFont('Arial','',6);
$pdf->Cell(60,9,"PAYMENT METHOD",1,0,'C','0');
$pdf->Cell(35,9,"DIRECT DEPOSIT",1,0,'C','0');
$pdf->SetFont('Arial','',8);
$pdf->Ln(4);
$pdf->Cell(80,5,$state,"LBR",0,'L','0');
if ($_POST['promotion'] != ''){
$pdf->Ln(7);
$pdf->Cell(60,9,"PROMOTION CODE USED: " . $_POST['promotion'],1,0,'L','0');
$pdf->Ln(8);
}else{
$pdf->Ln(15);
}
$pdf->SetFont('Arial','',6);
$pdf->Cell(30,7,"ITEM",1,0,'C','1');
$pdf->Cell(90,7,"DESCRIPTION",1,0,'C','1');
$pdf->Cell(25,7,"TAX",1,0,'C','1');
$pdf->Cell(25,7,"TAX AMT",1,0,'C','1');
$pdf->Cell(25,7,"AMOUNT",1,0,'C','1');
$pdf->SetFont('Arial','',8);
$pdf->Ln(7);
$pdf->Cell(30,5,$pdf->item,"1",0,'L','0');
$pdf->Cell(90,5,$pdf->description,"1",0,'L','0');
$pdf->Cell(25,5,"GST","1",0,'C','0');
$pdf->Cell(25,5,"$" . $pdf->gst,"1",0,'R','0');
$pdf->Cell(25,5,"$" . $pdf->amount,"1",0,'R','0');
$pdf->Ln(5);
$pdf->SetFont('Arial','',6);
$pdf->Cell(90,7,"TAX SUMMARY",1,0,'L','1');
$pdf->Cell(55,7);
$pdf->Cell(25,7,"SUBTOTAL","LTB",0,'L','1');
$pdf->Cell(25,7,"$" . $pdf->amount,"RTB",0,'R','1');
$pdf->Ln(7);
$pdf->SetFont('Arial','',6);
$pdf->Cell(90,7,"$" . $pdf->gst . " GST",1,0,'R','1');
$pdf->Cell(55,7);
$pdf->Cell(25,7,"TAX TOTAL","LTB",0,'L','1');
$pdf->Cell(25,7,"$" . $pdf->gst,"RTB",0,'R','1');
$pdf->Ln(7);
$pdf->SetFont('Arial','',6);
$pdf->Cell(90,7,"Thank you for your business",1,0,'L','1');
$pdf->Cell(55,7);
$pdf->Cell(25,7,"TOTAL","LTB",0,'L','1');
$pdf->Cell(25,7,"$" . $pdf->amount,"RTB",0,'R','1');
$pdf->Ln(15);
$pdf->SetFont('Arial','B',10);
$pdf->Cell(90,7,"Payment Information",0,0,'L','0');
$pdf->Ln(5);
$pdf->Cell(20,5,"So we can track your payment, please use the invoice number",0,0,'L');
$pdf->Ln(4);
$pdf->Cell(20,5,"above and your business name as a reference when paying us",0,0,'L');
$pdf->Ln(5);
$pdf->Cell(90,7,"Direct Deposit to:",0,0,'L','0');
$pdf->Ln(4);
$pdf->Cell(90,7,$pdf->bank,0,0,'L','0');
$pdf->Ln(4);
$pdf->Cell(90,7,"Acc. Name: " .$pdf->account_name,0,0,'L','0');
$pdf->Ln(4);
$pdf->Cell(90,7,"BSB: " .$pdf->bsb,0,0,'L','0');
$pdf->Ln(4);
$pdf->Cell(90,7,"Acc. No: " .$pdf->account_number,0,0,'L','0');
$pdf->Output("somefile.pdf");

patricktt
30-06-2009, 09:51 AM
the thing with fpdf is that it can take a while to get everything looking like you want it, because you have to program how you want it to output the pdf.. which if you have the html already on screen, can double your time..

the good thing with dompdf is that you provide it with the html page and it does the rest for you..

Vee
30-06-2009, 10:02 AM
Thanks Steve

::Scott::
30-06-2009, 10:11 AM
I have used dompdf quite a bit and recommend it, it's very easy to use and the results are impressive :)

+1 for dompdf! I use it and its great!

stevebramley
30-06-2009, 10:35 AM
awsome folks, I'll check it out! yeah it wasn't available when I did my pdf foray and I totally agree with the agony of painstakingly laying out the pdf by hand! No good.