是否可以使用Zend_Pdf将HTML转换为pdf? [英] Is possible convert HTML into pdf using Zend_Pdf?

查看:282
本文介绍了是否可以使用Zend_Pdf将HTML转换为pdf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有可能直接使用 HTML转换为使用Zend_Pdf的pdf文件,如果是的话,我该怎么做?

解决方案

Zend_PDF 无法生成基于HTML的PDF。但是您可以渲染视图并使用其他库将其转换为PDF。我已经使用 TCPDF 完成了相关工作。下面的小代码段:

  //SomeController.php 
$ this-> _helper-> layout-> ; disableLayout();

//设置内容在这里查看

//创建新的PDF文档
require_once('tcpdf / tcpdf.php');
$ pdf =新的TCPDF(PDF_PAGE_ORIENTATION,PDF_UNIT,PDF_PAGE_FORMAT,true,'UTF-8',false);

//整个TCPDF的设置都在这里
$ b $ htmlcontent = $ this-> view-> render('recipe / topdf.phtml');
//输出HTML内容
$ pdf-> writeHTML($ htmlcontent,true,0,true,0);
$ pdf-> lastPage();
$ pdf->输出(pdf-name.pdf,'D');


Is possible convert directly HTML into a pdf file using Zend_Pdf?, if so, How can I do that?

解决方案

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:

    //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');

这篇关于是否可以使用Zend_Pdf将HTML转换为pdf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆