是否可以使用 Zend_Pdf 将 HTML 转换为 pdf?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5183238/
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
Is possible convert HTML into pdf using Zend_Pdf?
提问by texai
Is possible convert directlyHTML into a pdf file using Zend_Pdf?, if so, How can I do that?
是否可以使用 Zend_Pdf将HTML直接转换为 pdf 文件?如果可以,我该怎么做?
采纳答案by Radek Benkel
Zend_PDF
isn't able to generate PDF based on HTML. But you can render view and use other library for convert it to PDF. I've done such thing with TCPDF. Little code snippet below:
Zend_PDF
无法基于 HTML 生成 PDF。但是您可以渲染视图并使用其他库将其转换为 PDF。我用TCPDF做过这样的事情。下面的小代码片段:
//SomeController.php
$this->_helper->layout->disableLayout();
//set content for view here
// create new PDF document
require_once('tcpdf/tcpdf.php');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
//whole TCPDF's settings goes here
$htmlcontent = $this->view->render('recipe/topdf.phtml');
// output the HTML content
$pdf->writeHTML($htmlcontent, true, 0, true, 0);
$pdf->lastPage();
$pdf->Output("pdf-name.pdf", 'D');
回答by Brendon-Van-Heyzen
tcpdf is a little limited when it comes to html, wkhtmltopdfuses webkit
tcpdf 在 html 方面有点受限,wkhtmltopdf使用 webkit
回答by James Yun
i've used dompdf https://github.com/dompdf/dompdfits pretty easy and straight forward. it even reads/formats css.
我使用了 dompdf https://github.com/dompdf/dompdf,它非常简单直接。它甚至可以读取/格式化 css。