在 php 中导出 PDF

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10496122/
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-24 22:20:14  来源:igfitidea点击:

PDF Export in php

phppdfformattingexportconverter

提问by Learner

Is there any possibility to write huge data in pdf without changing any ini modifications with less executing time..?

是否有可能在 pdf 中写入大量数据而不用更少的执行时间更改任何 ini 修改..?

Currently I'm using tcpdf plugin.

目前我正在使用 tcpdf 插件。

回答by Somnath Muluk

If your intention is to create a PDF from PHP, pdflib will help you.

如果您打算从 PHP 创建 PDF,pdflib 将为您提供帮助。

Otherwise, if you want to convertan HTML page to PDF via PHP, you'll find a little trouble outta here.

否则,如果您想通过 PHPHTML 页面转换为 PDF,您会发现这里有点麻烦。

So, the options I know are:

所以,我知道的选项是:

DOMPDF: PHP class that wraps the HTML and builds the PDF. Works good, customizable (if you know PHP), based on pdflib, and, if I remember correctly, it takes even some CSS. Bad news: slow when the HTML is big or very complex.

DOMPDF:包装 HTML 并构建 PDF 的 PHP 类。工作良好,可定制(如果您了解 PHP),基于 pdflib,而且,如果我没记错的话,它甚至需要一些 CSS。坏消息:当 HTML 很大或非常复杂时会变慢。

HTML2PS: same as DOMPDF, but this one converts first in .ps (GhostScript), then, in whatever format you need (PDF, JPEG, PNG). For me it is a little better then DOMPDF, but have the same speed problem. Oh, better compatibility with CSS.

HTML2PS:与 DOMPDF 相同,但此格式首先转换为 .ps(GhostScript),然后转换为您需要的任何格式(PDF、JPEG、PNG)。对我来说,它比 DOMPDF 好一点,但有相同的速度问题。哦,与CSS更好的兼容性。

Those two are PHP classes, but if you can install some software on the server, and access it through passthru()or system(), give a look to these too:

这两个是 PHP 类,但是如果您可以在服务器上安装一些软件,并通过passthru()或访问它system(),也可以看看这些:

wkhtmltopdf: based on WebKit (Safari's wrapper), it's really fast and powerful. Seems like it is the best one (at the moment) for HTML to PDF conversion on the fly, taking only 2 seconds for a 3 page XHTML document with CSS2. It's a recent project anyway, so the google.code page is often updated.

wkhtmltopdf:基于 WebKit(Safari 的包装器),它非常快速和强大。似乎它是最好的(目前)HTML 到 PDF 的动态转换,一个带有 CSS2 的 3 页 XHTML 文档只需要 2 秒钟。无论如何,这是一个最近的项目,因此 google.code 页面经常更新。

htmldoc: this one is a tank, it really never stops/crashes. The project seems dead, as of 2007, but if you don't need CSS compatibility this can be nice for you.

htmldoc:这是一辆坦克,它真的从不停止/崩溃。从 2007 年开始,该项目似乎已经死了,但是如果您不需要 CSS 兼容性,这对您来说可能会很好。

tcpdf- this is an enhanced and maintained version of fpdf. It has all the main Features of tpdfand it also has faster execution time with great output. For detailed tutorial on using the two most popular PDF generation classes: TCPDF and FPDF, please follow this link. I think you should continue using TCPDF.

tcpdf- 这是fpdf的增强和维护版本。它具有tpdf 的所有主要功能,并且还具有更快的执行时间和出色的输出。有关使用两个最流行的 PDF 生成类:TCPDF 和 FPDF 的详细教程,请点击此链接。我认为你应该继续使用 TCPDF

See these posts also:

另请参阅这些帖子:

  1. Convert HTML + CSS to PDF with PHP?
  2. Which one is the best PDF-API for PHP?
  3. Export a html into PDF in PHP?
  4. Writing HTML with PHP variables to PDF file?
  5. How to convert html into pdf with php?
  6. Tool for exporting html as pdf
  7. Converting HTML in PHP File to PDF File
  1. 使用 PHP 将 HTML + CSS 转换为 PDF?
  2. 哪个是 PHP 最好的 PDF-API?
  3. 在 PHP 中将 html 导出为 PDF?
  4. 将带有 PHP 变量的 HTML 写入 PDF 文件?
  5. 如何使用php将html转换为pdf?
  6. 将 html 导出为 pdf 的工具
  7. 将 PHP 文件中的 HTML 转换为 PDF 文件

回答by Adi

I highly recommend FPDF, very easy to use and you don't need any modifications.

我强烈推荐FPDF,非常易于使用,您不需要任何修改。

回答by gunnx

I've been using DOMPDF http://code.google.com/p/dompdf/as it handles HTML/CSS very well.

我一直在使用 DOMPDF http://code.google.com/p/dompdf/因为它可以很好地处理 HTML/CSS。

回答by Petah

You should use Webkit HTML to PDF http://code.google.com/p/wkhtmltopdf/

您应该使用 Webkit HTML 到 PDF http://code.google.com/p/wkhtmltopdf/

It simply requests the HTML page (generated from your PHP) and renders it to PDF (using the Webkit rendering engine, which is one of the best).

它只是请求 HTML 页面(从 PHP 生成)并将其呈现为 PDF(使用 Webkit 呈现引擎,这是最好的引擎之一)。

Hence it requires no extra resources on the PHP side.

因此,它不需要 PHP 端的额外资源。

回答by Bob

You could just use Zend Framework. If I'm not mistaken, there is a feature in the framework that allows you to create PDF's.

您可以只使用 Zend 框架。如果我没记错的话,框架中有一项功能可以让您创建 PDF。