是否可以使用 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 07:05:04  来源:igfitidea点击:

Is possible convert HTML into pdf using Zend_Pdf?

htmlzend-frameworkpdfzend-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_PDFisn'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。

回答by Rajan Rawal

Check out MPDF. The ultimate one. Create your html with inline css, store it in one php variable and echo to pdf file. you are done!!!

查看MPDF。终极一。使用内联 css 创建 html,将其存储在一个 php 变量中并回显到 pdf 文件。你完成了!!!