哪个是 PHP 最好的 PDF-API?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1648715/
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
Which one is the best PDF-API for PHP?
提问by coderex
回答by gpilotino
回答by velcrow
From the mpdfsite: "mPDF is a PHP class which generates PDF files from UTF-8 encoded HTML. It is based on FPDF and HTML2FPDF, with a number of enhancements."
来自mpdf站点:“mPDF 是一个 PHP 类,它从 UTF-8 编码的 HTML 生成 PDF 文件。它基于 FPDF 和 HTML2FPDF,具有许多增强功能。”
mpdf is superior to FPDF for language handling and UTF-8 support. For CJK support it not only supports font embedding, but font subsetting (so your CJK PDFs are not oversized). TCPDF and FPDF have nothing on the UTF-8 and Font support of mpdf. It even comes with some open source fonts as of version 5.0.
mpdf 在语言处理和 UTF-8 支持方面优于 FPDF。对于 CJK 支持,它不仅支持字体嵌入,还支持字体子集化(因此您的 CJK PDF 不会过大)。TCPDF 和 FPDF 对 mpdf 的 UTF-8 和字体支持没有任何作用。从 5.0 版开始,它甚至还带有一些开源字体。
回答by dan
This is just a quick review of how fPDF stands up against tcPDF in the area of performance at each libraries most basic functions.
这只是对 fPDF 在每个库最基本功能的性能方面如何与 tcPDF 相抗衡的快速回顾。
SPEED TEST
速度测试
17.0366 seconds to process 2000 PDF files using fPDF || 79.5982 seconds to process 2000 PDF files using tcPDF
使用 fPDF 处理 2000 个 PDF 文件需要 17.0366 秒 || 79.5982 秒使用 tcPDF 处理 2000 个 PDF 文件
FILE SIZE CHECK (in bytes)
文件大小检查(以字节为单位)
788 fPDF || 1,860 tcPDF
第788章 1,860 tcPDF
The code used was as identical as possible and renders just a clean PDF file with no text. This is also using the latest version of each library as of June 22, 2011.
使用的代码尽可能相同,并且只呈现一个没有文本的干净 PDF 文件。这也使用截至 2011 年 6 月 22 日的每个库的最新版本。
回答by Silver Moon
I found mpdf better than tcpdf in terms of html rendering. It can parse css styles much better and create pdf that look very similar to the original html.
我发现 mpdf 在 html 渲染方面比 tcpdf 更好。它可以更好地解析 css 样式并创建看起来与原始 html 非常相似的 pdf。
mpdf even supports css things like border-radius and gradient etc.
mpdf 甚至支持诸如边界半径和渐变等 css 东西。
I am surprised to see why mpdf is so less talked about when it comes to html to pdf.
我很惊讶地看到为什么 mpdf 在谈到 html 到 pdf 时很少被谈论。
Check out the examples here http://www.mpdf1.com/mpdf/index.php?page=Examples
在此处查看示例http://www.mpdf1.com/mpdf/index.php?page=Examples
I found it useful for designing invoices, receipts and simple prints etc. However the website itself says that pdfs generated from mpdf tend to be larger in size.
我发现它对设计发票、收据和简单的印刷品等很有用。但是网站本身说从 mpdf 生成的 pdf 往往更大。
回答by Mukesh Chapagain
Try TCPDF. I find it the best so far.
试试TCPDF。我觉得它是迄今为止最好的。
For detailed tutorial on using the two most popular pdf generation classes: TCPDF and FPDF.. please follow this link: PHP: Easily create PDF on the fly with TCPDF and FPDF
有关使用两个最流行的 pdf 生成类的详细教程:TCPDF 和 FPDF.. 请点击此链接:PHP:使用 TCPDF 和 FPDF 轻松即时创建 PDF
Hope it helps.
希望能帮助到你。
回答by Mike Valstar
Personally I prefer to use dompdffor simple PDF pages as it is very quick. you simply feed it an HTML source and it will generate the required page.
我个人更喜欢将dompdf用于简单的 PDF 页面,因为它非常快。你只需给它一个 HTML 源代码,它就会生成所需的页面。
however for more complex designs i prefer the more classic pdflibwhich is available as a pecl for PHP. it has greater control over designs and allows you do do more complex designs like pixel-perfect forms.
但是对于更复杂的设计,我更喜欢更经典的pdflib,它可以作为 PHP 的 pecl 使用。它可以更好地控制设计,并允许您进行更复杂的设计,例如像素完美的形式。
回答by Strae
http://sourceforge.net/projects/html2ps/, is the best if you need the css and 3c compatibily.
http://sourceforge.net/projects/html2ps/,如果您需要兼容 css 和 3c,这是最好的。
if you can install software on your server, i suggest you to use http://wkhtmltopdf.org/.
如果您可以在您的服务器上安装软件,我建议您使用http://wkhtmltopdf.org/。
There is also a drupal module using wkhtmltopdf :)
还有一个使用 wkhtmltopdf 的 drupal 模块 :)
PHP take many resources to convert html in pdf, imho, php is not the right language to do that (if you expect a large numbers of coversion or large files to convert)
PHP 需要很多资源来转换 pdf 中的 html,恕我直言,php 不是正确的语言(如果您希望转换大量的转换或大文件)
回答by txyoji
The Zend Framework's Zend_Pdfis really good. It's on par with pdflib in terms of control of output and complexity and is more portable because its a pure php solution. That said, its slower and uses more memory than pdflib. Pecl modules are always more efficient than a php solution.
Zend Framework 的Zend_Pdf非常好。它在控制输出和复杂性方面与 pdflib 不相上下,并且由于它是纯 php 解决方案,因此更具可移植性。也就是说,它比 pdflib 更慢并且使用更多的内存。Pecl 模块总是比 php 解决方案更有效。
DOMPdfis the easiest way to make a pdf quickly. Like Mike said, feed it html and it outputs a pdf. Under the hood, it has the option to use either r&ospdfor pdflibas the rendering engine.
DOMPdf是快速制作 pdf 的最简单方法。就像迈克说的,给它 html 并输出一个 pdf。在幕后,它可以选择使用r&ospdf或pdflib作为渲染引擎。
回答by Luká? Lalinsky
I personally generate XSL:FO from PHP and use Apache FOPto convert it to PDF. Not a PHP-native solution, not very efficient either, but it works well even if you need to generate PDF with very complex layouts.
我个人从 PHP 生成 XSL:FO 并使用Apache FOP将其转换为 PDF。不是 PHP 原生解决方案,效率也不是很高,但即使您需要生成具有非常复杂布局的 PDF,它也能很好地工作。

