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
Generate pdf from php(have to retrieve from mysql database)
提问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 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/