Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export a php page to pdf [duplicate]

I have a php page which consists of table data and a few funnel charts. I want to export the page to pdf with headers and footers.

Can anybody tell me how to export it using javascript or jquery or in any other form?

Thank You

like image 624
Mac Avatar asked Apr 17 '13 05:04

Mac


1 Answers

for using FPDF you can download from the link and for more information , Here's http://fpdf.org

after that you can integrate as follows..

<?php

require_once('fpdf.php');

class PDF extends FPDF
{
    function Header()
    {
        $query='your query';
        $row=mysql_fetch_assoc($query); // data from database 


        $this->SetXY(50,60);
        $this->Cell(45,6,'Name  :',1,1,'R');
        $this->SetXY(95,60);
        $this->Cell(80,6,$row['pdf_name'],1,1);

        $this->SetXY(50,66);
        $this->Cell(45,6,'Email Address  :',1,1,'R');
        $this->SetXY(95,66);
        $this->Cell(80,6,$row['pdf_email'],1,1);

        $this->SetXY(50,72);
        $this->Cell(45,6,'Question Paper Selected  :',1,1,'R');
        $this->SetXY(95,72);
        $this->Cell(80,6,$row['subject_sel'],1,1);

        $this->SetXY(50,78);
        $this->Cell(45,6,'Total Correct Answers  :',1,1,'R');
        $this->SetXY(95,78);
        $this->Cell(80,6,$row['right_answered'],1,1);

        $this->SetXY(50,84);
        $this->Cell(45,6,'Percentage  :',1,1,'R');
        $this->SetXY(95,84);
        $this->Cell(80,6,$row['percentage']."%",1,1);

        $this->Ln(20);
    }
    function Footer()
    {
        $this->SetY(-15);
        $this->SetFont('Arial','I',8);
        $this->Cell(0,10,'abc according to you',0,0,'C');
    }
}
$pdf=new PDF('P','mm',array(297,210));
$pdf->Output($name.'.pdf','D');
?>

you can edit according to your need, it will display record in the form of table and generate it to pdf. hope it will helpful to you.

update:

for image

$this->Image('image path',80,30,50);
like image 95
Yadav Chetan Avatar answered Oct 17 '22 06:10

Yadav Chetan