从 php 生成 PDF 报告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2417315/
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 report from php
提问by Anand Sunderraman
I am using php code to query to a database and the results will be used to generate a report.
我正在使用 php 代码查询数据库,结果将用于生成报告。
If I want the report to be generated in a pdf format how should I do it ?
如果我想以 pdf 格式生成报告,我应该怎么做?
回答by Silver Light
If you need UTF support in your PDF file, consider tcpdflibrary.
如果您的 PDF 文件需要 UTF 支持,请考虑tcpdflibrary。
Download it from here: http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf
从这里下载:http: //www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf
And in your script:
在你的脚本中:
<?php
//include files
require_once($_SERVER['DOCUMENT_ROOT'].'/tcpdf/config/lang/eng.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/tcpdf/tcpdf.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
//add some content using class methods
//Close and output PDF document
$pdf->Output('filename.pdf', 'I');
?>
回答by Pentium10
回答by rael_kid
回答by Fabian
I've used TCPDF (http://www.tcpdf.org/) for my last project. It worked pretty good but the next time im going for a html to pdf converter, simply because designing the report (converting to pdf draw statements) was such a time sink.
我在上一个项目中使用了 TCPDF ( http://www.tcpdf.org/)。它工作得很好,但下次我要使用 html 到 pdf 转换器时,仅仅是因为设计报告(转换为 pdf 绘图语句)太浪费时间了。
So i would suggest http://sourceforge.net/projects/html2fpdf/

