编程语言
首页 > 编程语言> > php-在CodeIgniter中使用DOMpdf生成PDF

php-在CodeIgniter中使用DOMpdf生成PDF

作者:互联网

我正在尝试使用dompdf生成pdf.

 <?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Dompdf_test extends CI_Controller {

    public function index() {
        // Load all views as normal
        //$this->load->view('phptopdfexample');
        $this->all_movements();
        // Get output html
        $html = $this->output->get_output();

        // Load library
        $this->load->library('dompdf_gen');

        // Convert to PDF
        $this->dompdf->load_html($html);

        $this->dompdf->render();
        $min = 1;
        $max = 1000;
        $name = rand($min, $max);
        $this->dompdf->stream($name . '.pdf');
    }

    public function all_movements() {
        $data['stocks'] = $this->inventory->getdepartmentalmovements();
        $data['meds'] = $this->inventory->get_meds();

        $this->load->view('deptartmental_issue_pdf', $data);
    }

}

运行脚本时,出现内部服务器错误,并显示以下错误:
遇到PHP错误

严重程度:警告

消息:非法字符串偏移量“十六进制”

文件名:include / style.cls.php

行号:1422

我怎么解决这个问题?

解决方法:

dompdf 0.6中已解决此问题

或者您可以通过在以下条件中添加条件来更正此问题:

dompdf / include / style.cls.php

然后搜索if(is_null($col))(可能是:1422行或其附近)

if ( is_null($col) )
$col = self::$_defaults["color"];
//see __set and __get, on all assignments clear cache, not needed on direct set through __set
$this->_prop_cache["color"] = null;
$this->_props["color"] = $col["hex"];
}

也添加此条件,然后尝试.

if (is_array($col))
     $this->_props["color"] = $col["hex"];

标签:codeigniter,dompdf,php
来源: https://codeday.me/bug/20191029/1963820.html