简体   繁体   English

使用PHP将MySQL数据库表内容导出到PDF文件

[英]export mysql database table contents on to a PDF file using php

How to export MySQL database table contents on to a PDF file. 如何将MySQL数据库表内容导出到PDF文件。 It has to be displayed in the website as download/print data . 它必须作为download/print data显示在网站上。 When the customer click on that he/she has to get the PDF opened or an option to download the PDF with all the contents of the table using php. 当客户单击该按钮时,他/她必须打开PDF或使用php下载包含表中所有内容的PDF的选项。

    <?php
require('fpdf17/fpdf.php');
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',10);
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('times','B',10);
$pdf->Cell(25,7,"Stud ID");
$pdf->Cell(30,7,"Student Name");
$pdf->Cell(40,7,"Address");
$pdf->Cell(30,7,"Class");
$pdf->Cell(30,7,"Phone No");
$pdf->Cell(30,7,"E-mail");
$pdf->Ln();
$pdf->Cell(450,7,"----------------------------------------------------------------------------------------------------------------------------------------------------------------------");
$pdf->Ln();

        include ('db.php');
        $sql = "SELECT studid,name,address,class,phone,email FROM studinfo";
        $result = mysql_query($sql);

        while($rows=mysql_fetch_array($result))
        {
            $studid = $rows[0];
            $name = $rows[1];
            $address = $rows[2];
            $class = $rows[3];
            $phone = $rows[4];
            $email = $rows[5];
            $pdf->Cell(25,7,$studid);
            $pdf->Cell(30,7,$name);
            $pdf->Cell(40,7,$address);
            $pdf->Cell(30,7,$class);
            $pdf->Cell(30,7,$phone);
            $pdf->Cell(30,7,$email); 
            $pdf->Ln(); 
        }
$pdf->Output();
?>

You should make use of PDF creator libraries like: 您应该使用PDF创建者库,例如:

  1. FPDF PDF格式
  2. TCPDF 技术合作伙伴
  3. EzPDF PDF格式

All three are easy to learn in the order I've put. 按照我的顺序,所有这三个都很容易学习。 The documentation of FPDF and EzPDF are very neat and clean. FPDF和EzPDF的文档非常整洁。 But TCPDF Documentation is not that readable. 但是TCPDF文档不那么可读。

You can use http://www.tcpdf.org/ to create your own PDF. 您可以使用http://www.tcpdf.org/创建自己的PDF。 The examples and the doc tabs will help you ^^ ( http://www.tcpdf.org/doc/code/classTCPDF.html for all the methods) examples和文档标签将帮助您^^(有关所有方法,请参见http://www.tcpdf.org/doc/code/classTCPDF.html

You can create a HTML table will all your data and put it in your PDF using the WriteHTML() method. 您可以使用WriteHTML()方法创建一个将所有数据都存储到HTML表中的表格。

Take a look at http://www.tcpdf.org/ . 看一下http://www.tcpdf.org/ I never heard about out of box way to print mysql table data into PDF, but with TCPDF you can programmatically build a PDF file with table filled with data inside it. 我从未听说过将MySQL表格数据打印为PDF的即用型方法,但是使用TCPDF,您可以以编程方式构建一个PDF文件,并在其中填充数据。 It also allows to output document created on the fly easily into a browser. 它还允许将即时创建的文档轻松输出到浏览器中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM