1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

how to convert html output to pdf

Discussion in 'PHP' started by vanisri, Feb 6, 2007.

  1. vanisri

    vanisri New Member

    Joined:
    Feb 6, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    Well, I guess you cannot convert HTML to PDF through PHP, but what you can do is create PDF with PHP/Perl.
     
  3. vanisri

    vanisri New Member

    Joined:
    Feb 6, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    can u provide code for creating pdf with php/perl
     
  4. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    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();
     
     
  5. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    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"));
     

Share This Page