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