php - 在 CodeIgniter 中使用 DOMpdf 生成 PDF

标签 php codeigniter dompdf

我正在尝试使用 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 错误

严重性:警告

消息:非法字符串偏移'hex'

文件名: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"];

关于php - 在 CodeIgniter 中使用 DOMpdf 生成 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21478837/

相关文章:

php - 使用 Codeigniter 在数据库中存储 HTML 标签(包括 PHP 脚本)

html - 使用 dompdf 生成 PDF 时文本溢出表格

php - 如何通过Ajax发送php变量仅当它不为空时

php - PHP 操作码缓存是否与 __autoload 一起使用?

php - 购物车价格规则的类层次结构

php - 在sql查询中创建计数器

PHP SQL更新查询

javascript - Codeigniter ajax插入成功重定向

html - 如何在dompdf中自动添加 "New Page"

php - 为什么我的代码出现 fatal error : Uncaught exception 'DOMPDF_Exception' with message 'Frame not found in cellmap