php 使用php将mysql数据库表内容导出到PDF文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16604944/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:25:56  来源:igfitidea点击:

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

phpmysqldatabasepdf

提问by user2371258

How to export MySQL database table contents on to a PDF file. It has to be displayed in the website as 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.

如何将 MySQL 数据库表内容导出到 PDF 文件。它必须在网站上显示为download/print data. 当客户点击它时,他/她必须打开 PDF,或者选择使用 php 下载包含表格所有内容的 PDF。

采纳答案by Viktor S.

Take a look at 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. It also allows to output document created on the fly easily into a browser.

看看http://www.tcpdf.org/。我从未听说过将 mysql 表数据打印为 PDF 的开箱即用方式,但是使用 TCPDF,您可以以编程方式构建一个 PDF 文件,其中表中填充有数据。它还允许将动态创建的文档轻松输出到浏览器中。

回答by Peter Louis

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

回答by Elavarasan M Lee

You should make use of PDF creator libraries like:

您应该使用 PDF 创建者库,例如:

  1. FPDF
  2. TCPDF
  3. EzPDF
  1. FPDF
  2. TCPDF
  3. 电子PDF

All three are easy to learn in the order I've put. The documentation of FPDF and EzPDF are very neat and clean. But TCPDF Documentation is not that readable.

按照我的顺序,这三个都很容易学习。FPDF 和 EzPDF 的文档非常整洁干净。但是 TCPDF 文档不是那么可读。

回答by Yoh

You can use http://www.tcpdf.org/to create your own PDF. The examplesand the doc tabs will help you ^^ (http://www.tcpdf.org/doc/code/classTCPDF.htmlfor all the methods)

您可以使用http://www.tcpdf.org/创建自己的 PDF。在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 表格,将您的所有数据放入您的 PDF 中。