hi, I need to make a small invoice system. Already have most of the back end done. And the system needs to let user insert their own HTML template for the invoice generation. Which finally converts the output HMTL to a PDF and send it off as attachment via email. I already have everything else done, but not the HTML to PDF part. I'm pretty much stuck with basic scripting languages such as php and perl. Does anyone know how to properly convert HTML to PDF in php (or if must, perl)? regards, vanisri
Well, I guess you cannot convert HTML to PDF through PHP, but what you can do is create PDF with PHP/Perl.
Download FPDF from http://www.fpdf.org/. Example code PHP: require_once("fpdf/fpdf.php"); $pdf=new PDF('P','mm','A4'); $pdf->SetTopMargin(20); $pdf->SetLeftMargin(25); $pdf->AddPage(); $pdf->SetFont('Arial','',10); $pdf->Cell(0,30,'',0,1); //blank space $pdf->Cell(0,8,"$curdate",0,1,'L'); $pdf->Output();
I have also had success with pdf-php (ezpdf). Sample code: PHP: require "pdf/class.ezpdf.php"; ... $sort = "Sorted by ".$sorting [$mOrder]; $header = "Report -- Weekly Sales"; $letterhead = "Fuccillo Chevrolet"; $reportdate = date ("l, F j, Y"); $sort = "Sorted by ".$sorting [$mOrder]; $title = "Report for Week of ".$theDate; $nCols = 15; $doc =& new Cezpdf ('a4', 'landscape'); $doc->selectFont('pdf/fonts/Helvetica.afm'); $doc->ezStartPageNumbers (450,15,10,'','',1); $doc->ezText ($letterhead, "16", array ("justification" => "center")); $doc->ezSetDy (-5); $doc->ezText ($header, "14", array ("justification" => "center")); $doc->ezText ($reportdate, "10", array ("justification" => "center")); $doc->ezText ($title, "12", array ("justification" => "center"));