从 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

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

Generate PDF report from php

phppdf

提问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

Look into html2pdf

查看html2pdf

Create your report as html and then run the code to transform into PDF. You don't need to know the language to generate the PDF blocks. Submitted forms work out cool too.

将您的报告创建为 html,然后运行代码以转换为 PDF。您无需了解生成 PDF 块的语言。提交的表格也很酷。

回答by rael_kid

You can also use FPDF, I've used that for several projects. In the beginning you will be annoyed a lot, but when you get used to it, it will get easier to create pdf's :)

您也可以使用FPDF,我已将其用于多个项目。一开始你会很恼火,但是当你习惯了,创建pdf会变得更容易:)

回答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/

所以我建议http://sourceforge.net/projects/html2fpdf/