使用 PHP 创建 PDF 的最佳方式

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

Best way to create a PDF with PHP

phppdf

提问by Samuurai

I've been reading up on creating a PDF file with PHP and am wondering what the easiest option is.

我一直在阅读有关使用 PHP 创建 PDF 文件的信息,并且想知道最简单的选项是什么。

  1. Create a PDF template, open it and replace placeholder text -- which function do I use to open an existing PDF for editing?

  2. Create a PDF template and place text on it using co-ordinates

  3. Create a HTML document then convert it to PDF using some sort of free tool?

  4. Create a PDF from scratch using PHP (this seams like a time consuming way to do it).

  1. 创建一个 PDF 模板,打开它并替换占位符文本——我使用哪个功能打开现有的 PDF 进行编辑?

  2. 创建 PDF 模板并使用坐标在其上放置文本

  3. 创建一个 HTML 文档,然后使用某种免费工具将其转换为 PDF?

  4. 使用 PHP 从头开始​​创建 PDF(这看起来像是一种耗时的方法)。

采纳答案by Sarfraz

The one that i know of as being best is the FPDF. It is great open-source solution for creating all sorts of PDF layouts. Thanks

我所知道的最好的是FPDF。它是用于创建各种 PDF 布局的出色开源解决方案。谢谢

See FPDF tutorials
And scripts

查看 FPDF 教程
和脚本

回答by Mukesh Chapagain

If you want very advanced features in PDF creation then try TCPDF. If you want just minimal features of PDF creation and want a smaller in size class then try FPDF.

如果您想要 PDF 创建中的非常高级的功能,请尝试TCPDF。如果您只想要创建 PDF 的最小功能并想要更小的尺寸类,请尝试FPDF

The following link has an article describing these two PDF generating class libraries: Easily create PDF with PHP

以下链接有一篇文章描述了这两个PDF生成类库:用PHP轻松创建PDF

回答by Tim

Time consuming but best results.. I use Fpdf

耗时但效果最好.. 我使用Fpdf

I have also had some success with html2pdfwhich tries to convert html to a pdf document.

我在尝试将 html 转换为 pdf 文档的html2pdf方面也取得了一些成功。