php 从php生成pdf(必须从mysql数据库中检索)

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

Generate pdf from php(have to retrieve from mysql database)

phpdatabasepdf

提问by ssss05

I have already created a report using list of data from my database. i have a button in that page "Click to generate Pdf". if i click that button the same report have to come as pdf report. now i need to convert that reports as PDF. i have googled past some days but i couldn't find the answers. all are saying and giving values directly into tables and they were generated it. But I need retrieve it directly from my database. i wanna to get it directly from queries....

我已经使用我的数据库中的数据列表创建了一个报告。我在该页面中有一个按钮“单击以生成 Pdf”。如果我点击那个按钮,同样的报告必须以 pdf 报告的形式出现。现在我需要将该报告转换为 PDF。我已经用谷歌搜索了几天,但我找不到答案。所有人都在说并将值直接放入表格中,然后它们就生成了。但我需要直接从我的数据库中检索它。我想直接从查询中获取它....

If any one know means kindly give your answers. hope you guys got my ques..

如果有人知道意味着请给出您的答案。希望你们有我的问题..

Thanks in Advance.

提前致谢。

Update : here is my script pdf.php

更新:这是我的脚本 pdf.php

<?php
include ('connection.php');
require('fpdf.php');

$joined = $_GET['joined'];
list($ZoneNo, $InstituteNo, $Year) = split('[,]', $joined);
//echo "ZoneNo: $ZoneNo; Institute: $InstituteNo; Year: $Year<br />\n";

$pdf=new FPDF();
$pdf->AddPage();

$pdf->SetFont('Arial','B',10);

$pdf->Ln();
$pdf->Ln();

$pdf->SetFont('Arial','B',10);
$pdf->Cell(20,15,"No");
$pdf->Cell(50,15,"Institute Name");
$pdf->Cell(50,15,"Course Name");
$pdf->Cell(50,15,"No. Of Students");
$pdf->Cell(50,15,"Year");
$pdf->Ln();
$pdf->Cell(450,3,"--------------------------------------------------------------------------------------------------------------------------------------------------------");


        $sql = "SELECT im.InstituteName,cm.CourseName,COUNT(sm.CourseNo),sm.Year FROM student_master sm,course_master cm,institute_master im WHERE ((sm.Year='".$Year."') AND (sm.InstituteNo='".$InstituteNo."') AND (sm.ZoneNo = '".$ZoneNo."')) AND (im.InstituteNo = sm.InstituteNo) AND (cm.CourseNo = sm.CourseNo) GROUP BY sm.CourseNo ORDER BY im.InstituteName,cm.CourseName";
        $result = mysql_query($sql);
        $No = 0;
        while($rows=mysql_fetch_array($result))
        {
            $No = $No + 1;
            $InstituteName = $rows[0];
            $CourseName = $rows[1];
            $Total = $rows[2];
            $Year = $rows[3];
            $pdf->Cell(20,15,"{$No}");
            $pdf->Cell(50,15,"{$InstituteName}");
            $pdf->Cell(50,15,"{$CourseName}");
            $pdf->Cell(50,15,"{$Total}");
            $pdf->Cell(50,15,"{$Year}");    
        }

$pdf->Output();

?>

note you guys here am getting only the output as

注意你们这里只得到输出

No InstituteName Course name No. of students Year

无 学院名称 课程名称 学生人数 年份

can you explain it now guys????

你现在能解释一下吗????

Guys Check this link http://www.fpdf.de/downloads/addons/30/if you have problems

如果您有问题,请检查此链接http://www.fpdf.de/downloads/addons/30/

采纳答案by Roman

try FPDF liberary as mentioned by diEcho above. You can find the Tutorials on their website. Here's a complete example of exporting data from mysql using the FPDF:

尝试上面 diEcho 提到的 FPDF 库。你可以在他们的网站上找到教程。这是使用 FPDF 从 mysql 导出数据的完整示例:

http://www.fpdf.de/downloads/addons/30/

http://www.fpdf.de/downloads/addons/30/

Also here: http://www.weberdev.com/get_example-3720.html

也在这里:http: //www.weberdev.com/get_example-3720.html

Hope it helps

希望能帮助到你

回答by Cudos

You could also try dompdf

你也可以试试dompdf

回答by Jason

PDF Report Writing

PDF报告写作

Step 1. Query your database

步骤 1. 查询您的数据库

Step 2. Format a HTML Report

步骤 2. 格式化 HTML 报告

Step 3. WKhtmltopdf the report into a pdf, serve for download

Step 3. WKhtmltopdf 将报告转成pdf,供下载

WKhtmltopdf will take a html page, use web kit to render it and output it as a PDF file

WKhtmltopdf 将获取一个 html 页面,使用 web kit 渲染它并将其输出为 PDF 文件

See here: http://code.google.com/p/wkhtmltopdf/

请参阅此处:http: //code.google.com/p/wkhtmltopdf/

回答by sunpietro

You should create PDF template (with HTML) and then query the database. Without template you can't organize the data.
You can use mPDFlibrary (my favorite).

您应该创建 PDF 模板(使用 HTML),然后查询数据库。没有模板,您将无法组织数据。
您可以使用mPDF库(我最喜欢的)。