【问题标题】:DOMPDF + Codeigniter, library upgraded, but now not workingDOMPDF + Codeigniter,库升级,但现在不工作
【发布时间】:2017-06-06 16:41:06
【问题描述】:

我一直在 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”

任何解决方案都将不胜感激

感谢

【问题讨论】:

    标签: codeigniter dompdf


    【解决方案1】:

    请先试试这个例子。只需将其存储在 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 目录路径即可。

    【讨论】:

    • 我已经通过将当前版本升级到最新版本解决了这个问题。
    【解决方案2】:

    我自己通过将 dompdf 版本上传到最新版本来解决这个问题,虽然它是 beta 版,但现在似乎一切正常。

    【讨论】:

      猜你喜欢
      • 2017-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-18
      • 1970-01-01
      • 1970-01-01
      • 2022-10-20
      • 1970-01-01
      相关资源
      最近更新 更多