php 如何使用PHP脚本创建动态包含的PDF?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6965430/
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
how to create PDF of dynamic contain using PHP script?
提问by vikas rane
Data is generated dynamically by using php, and displayed on browser in specified Design format; we need to generate PDF of that design format with dynamic data?
数据使用php动态生成,并以指定的Design格式显示在浏览器上;我们需要使用动态数据生成该设计格式的 PDF 吗?
we have data in php Sting, want to convert data string in PDF.
我们在 php Sting 中有数据,想将数据字符串转换为 PDF。
$str="<html><body>
<table width='100%' cellspacing='0' cellpadding='0'>
<tr>
<td width='3%'> </td>
<td width='98%' align='left'><br><img src='abs-path' border='0' alt='logo'>
<br>
<span class='style3'>Dear ".$name.",<br />
<p>Many thanks for your Interest
<br />
<br>
Thanking You,<br />
Secretariat <br>
".$addr."<br>
</span></td>
</tr>
</table>
</body>
</html>";
we have tried pdf function but its not working, when we call image dynamically using php. Also we have checked previously asked question regarding php-pdf, but still not able to solve the problem. please help us to generate PDF using php.
我们已经尝试过 pdf 函数,但它不起作用,当我们使用 php 动态调用图像时。我们也检查了之前提出的有关 php-pdf 的问题,但仍然无法解决问题。请帮助我们使用 php 生成 PDF。
回答by Rukmi Patel
回答by Lukas Knuth
To generate a PDF-File using PHP is a task which is often done using a PHP-Library like:
使用 PHP 生成 PDF 文件是一项通常使用 PHP 库完成的任务,例如:
These two projects are the most common and both are up to date (support UTF-8 for example) and free. If you already use one of the above, please be more specific about what problem you're facing and what error-messages come up.
这两个项目是最常见的,并且都是最新的(例如支持 UTF-8)并且是免费的。如果您已经使用上述之一,请更具体地说明您面临的问题以及出现的错误消息。
Both those library's use pure PHP to generate the PDF so you don't need to have "PDFlib" installed, which is used by the standard PDF-functions offered by PHP.
这两个库都使用纯 PHP 来生成 PDF,因此您不需要安装“PDFlib”,PHP 提供的标准 PDF 函数会使用它。
回答by cweiske
At work we use html2ps, which has one big advantage over all the other solutions: You don't need to write PDF specific code but can re-use the HTML you generated anyway. Also, this is easier to debug and automatically spreads the contents on several pages.
在工作中,我们使用html2ps,它比所有其他解决方案有一个很大的优势:您不需要编写特定于 PDF 的代码,但无论如何都可以重新使用您生成的 HTML。此外,这更易于调试并自动将内容分布在多个页面上。
回答by kiran tej
Hiii, I feel its better to use the FPDF.It's available at www.fpdf.org
嗨,我觉得使用 FPDF 更好。它可以在 www.fpdf.org 上找到
回答by Bhavik
Try using the mpdf it is best.. below is the url for the same http://www.mpdf1.com/mpdf/index.php
尝试使用 mpdf 最好.. 下面是相同 http://www.mpdf1.com/mpdf/index.php 的网址