DOMPDF + Codeigniter,库已升级,但现在无法正常工作

时间:2012-11-29 15:44:46

标签: codeigniter dompdf

我一直在codeigniter中使用旧版本的dom pdf来生成pdf,最近我将核心dompdf目录更改为更新版本的dompdf-0.5.2.zip。 下面是我用来连接dompdf类的代码:

class Pdf{

var $_dompdf = NULL;

/**
 * Constructor Method
**/
function __construct(){
    ini_set("memory_limit", "1G");
    require_once("Dompdf/dompdf_config.inc.php");
    if(is_null($this->_dompdf)){
        $this->_dompdf = new DOMPDF();
    }
}

/**
 * HTML to PDF Conversion method
**/
function convert_html_to_pdf($_html, $_filename = '', $_stream = false, $_orientation = "portrait"){
    $this->_dompdf->set_paper("a4", $_orientation);
    $this->_dompdf->load_html($_html);
    $this->_dompdf->render();
    if($_stream){
        $this->_dompdf->stream($_filename);
    } else{
        file_put_contents($_filename, $this->_dompdf->output()); 
    }
}

}

现在,当我尝试生成pdf时,它会出现以下错误: 致命错误:第21行的D:\ xampp \ htdocs \ app \ application \ libraries \ Pdf.php中找不到类'DOMPDF'

任何解决方案都将受到赞赏

感谢名单

2 个答案:

答案 0 :(得分:0)

请先试试这个例子。只需将其存储在xampp的htdocs目录下的文件中或您正在使用的任何服务器上。

<?php
require_once("dompdf_config.inc.php");

$html =
 '<html><body>'.
 '<p>Put your html here, or generate it with your favourite '.
 'templating system.</p>'.
 '</body></html>';

 $dompdf = new DOMPDF();
 $dompdf->load_html($html);
 $dompdf->render();
 $dompdf->stream("sample.pdf");

?>

只需根据您的要求更改dompdf目录路径。

答案 1 :(得分:0)

我通过将dompdf版本上传到最新版本来解决这个问题,虽然它是测试版,但现在看起来都很完美。