如何从 MySQL 表数据 PHP 创建 PDF 文档

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13740602/
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 05:58:42  来源:igfitidea点击:

How can I create a PDF document from MySQL table data PHP

phpmysqldatabasepdf

提问by mukamaivan

I want to get data from the MySQL data base and make and create a PDF file of the data.

我想从 MySQL 数据库中获取数据并制作和创建数据的 PDF 文件。

Here is my code, it saving the PDF file but it can not be opened.

这是我的代码,它保存了 PDF 文件,但无法打开。

<?php  
$host = 'localhost';
$user = 'root';
$pass = 'xxxx';
$db = 'db';

$link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
mysql_select_db($db) or die("Can not connect.");

$query = "SELECT childID,sex from child ";  

$result = mysql_query($query) or die('Error, query failed'); 

    while(mysql_fetch_array($result))  
    {  
        header("Content-length: $size"); 
        header("Content-type: $type"); 
        header("Content-Disposition: inline; filename=$username-$description.pdf"); 
    } 
    echo $content;
    mysql_close($link); 
    exit; 
?>

回答by Developer-Sid

Use any of the following php scripts to generate dynamic PDF documents

使用以下任一php脚本生成动态PDF文档

FPDF: http://www.fpdf.org/

FPDF:http://www.fpdf.org/

TCPDF: http://www.tcpdf.org/

TCPDF:http://www.tcpdf.org/

回答by Uttam Kadam

You can use DOMPDF. for more details look at the :

您可以使用 DOMPDF。有关更多详细信息,请查看:

http://code.google.com/p/dompdf/downloads/detail?name=dompdf_0-6-0_beta3.zip

http://code.google.com/p/dompdf/downloads/detail?name=dompdf_0-6-0_beta3.zip