php 从当前 HTML 页面创建 PDF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13241403/
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
Create PDF from current HTML page
提问by Daryl Gill
Possible Duplicate:
Convert HTML + CSS to PDF with PHP?
I'm on a basic Apache with no extensions apart from default enabled and I want to create a PDF file from the current page.
我在一个基本的 Apache 上,除了默认启用之外没有扩展,我想从当前页面创建一个 PDF 文件。
The current page is PHP echoing out some variables but I want to create a PDF document from the HTML and text currently shown on the page.
当前页面是 PHP 回显一些变量,但我想从页面上当前显示的 HTML 和文本创建一个 PDF 文档。
Something like WHMCS quote system.
类似WHMCS报价系统的东西。
采纳答案by ajtrichards
You could use a third party solution such as:
您可以使用第三方解决方案,例如:
http://www.web2pdfconvert.com/
http://www.web2pdfconvert.com/
http://html-pdf-converter.com/
http://html-pdf-converter.com/
I'd recommend pdfcrowd.com - it has an API that you can use and i've used the service before and not had any problems.
我推荐 pdfcrowd.com - 它有一个您可以使用的 API,我以前使用过该服务并且没有任何问题。
回答by mas-designs
回答by Tim Withers
Look into FPDF, TCPDF, DomPDF, or any other PHP PDF library.
查看FPDF、TCPDF、DomPDF或任何其他 PHP PDF 库。
FPDF is very lightweight, and could be perfect for you if you are just echoing out variables.
FPDF 非常轻量级,如果您只是回显变量,它可能非常适合您。
TCPDF is much more HTML->PDF in terms of syles and css features, but the file size is a bit bigger. It could be used to easily build invoices and make them look nice.
TCPDF 在 syles 和 css 功能方面更像是 HTML->PDF,但文件大小要大一些。它可用于轻松构建发票并使它们看起来不错。
I haven't used DomPDF personally, so I won't comment on it, but it can get the job done.
我个人没有使用过 DomPDF,所以我不会评论它,但它可以完成工作。
回答by galchen
I've used TCPDF to create a PDF from HTML. I think DOMPDF also does that
我已经使用 TCPDF 从 HTML 创建了 PDF。我认为 DOMPDF 也这样做
you have a few options:
你有几个选择:
http://php.net/manual/en/book.pdf.php
http://php.net/manual/en/book.pdf.php
FPDF: http://www.fpdf.org/
FPDF:http://www.fpdf.org/
TCPDF: http://www.tcpdf.org/
TCPDF:http://www.tcpdf.org/
DOMPDF: http://code.google.com/p/dompdf/
DOMPDF:http: //code.google.com/p/dompdf/
回答by clement
回答by h00ligan
The only pure PHP solution I've tested is mPDFand it worked pretty well for my purpose. It takes HTML/CSS input at generates a PDF from that.
我测试过的唯一纯 PHP 解决方案是mPDF,它对我的目的非常有效。它需要 HTML/CSS 输入,然后从中生成 PDF。
It requires a lot of memory so you'll have to increase the memory limit for the script. The settings that worked for me were:
它需要大量内存,因此您必须增加脚本的内存限制。对我有用的设置是:
ini_set('memory_limit', '1024M');
ini_set('pcre.backtrack_limit', 2000000);

