Go4Expert

Go4Expert (http://www.go4expert.com/)
-   PHP (http://www.go4expert.com/forums/php/)
-   -   how to convert html output to pdf (http://www.go4expert.com/forums/convert-html-output-pdf-t2887/)

vanisri 6Feb2007 16:23

how to convert html output to pdf
 
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

pradeep 6Feb2007 17:36

Re: how to convert html output to pdf
 
Well, I guess you cannot convert HTML to PDF through PHP, but what you can do is create PDF with PHP/Perl.

vanisri 6Feb2007 17:39

Re: how to convert html output to pdf
 
can u provide code for creating pdf with php/perl

pradeep 6Feb2007 17:46

Re: how to convert html output to pdf
 
Download FPDF from http://www.fpdf.org/.

Example code
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();


DaWei 12Feb2007 19:45

Re: how to convert html output to pdf
 
I have also had success with pdf-php (ezpdf). Sample code:
PHP Code:

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")); 



All times are GMT +5.5. The time now is 14:29.