php - 将 php 页面导出为 pdf

标签 php javascript jquery pdf-generation

<分区>

我有一个由表格数据和一些漏斗图组成的 php 页面。我想将页面导出为带有页眉和页脚的 pdf。

谁能告诉我如何使用 javascript 或 jquery 或任何其他形式导出它?

谢谢

最佳答案

要使用 FPDF,您可以从链接下载更多信息,这里是 http://fpdf.org

之后你可以按如下方式整合..

<?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');
?>

您可以根据需要进行编辑,它会以表格的形式显示记录并生成pdf。希望对您有所帮助。

更新:

图片

$this->Image('image path',80,30,50);

关于php - 将 php 页面导出为 pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16051877/

相关文章:

php - 如何在docker容器中连接我的主机mysql?

php - 为对象动态添加私有(private)属性

php - 在 <img> 标签中显示以 # 开头的图像

jquery - 获取更改时的单选按钮值不起作用

javascript - 我如何检查 Javascript 中的唯一性?

php - 需要帮助用 PHP 剪切字符串

javascript - 如何居中和缩放对象threejs

javascript - 在构造函数中绑定(bind)方法

javascript - 如何使用 Typescript/JS 查找数组中对象值出现的前 n 次?

jquery - spring mvc中使用@PathVariable时ajax不起作用