【问题标题】:Export a php page to pdf [duplicate]将php页面导出为pdf [重复]
【发布时间】:2013-04-09 17:36:21
【问题描述】:

我有一个 php 页面,其中包含表格数据和一些漏斗图。我想将页面导出为带有页眉和页脚的 pdf。

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

谢谢

【问题讨论】:

  • 试试mPdffPdf PHP 库...
  • 您可以使用DOMPDFTCPDF 导出pdf。
  • 当您使用 PHP 生成页面时,我认为最好的选择是使用 TCPDF 包。它具有如此强大的功能,可以进行如此多的自定义并且更易于配置。

标签: php javascript jquery pdf-generation


【解决方案1】:

对于使用 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);

【讨论】:

  • 谢谢@Yadav 我发现它对我的要求很有用
  • 你能告诉我如何使用 fpdf 添加表格和图形....我有一个页面,其中有一些表格和漏斗图一个接一个...让我知道如何添加它以上代码
  • @mac 你的图表是图片形式的吗?
  • @你必须手动制作表格,因为我已经根据我的需要制作了它,为了图像让我给你方法
  • 漏斗图是图像格式..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-03
  • 1970-01-01
  • 1970-01-01
  • 2017-04-15
相关资源
最近更新 更多