Php DOMPD在codeigniter中生成损坏的PDF
我正在使用dompdf在codeigniter应用程序中生成pdf, 当我打开pdf时,它的给出错误 " 我检查了所有stackoverflow的资料Php DOMPD在codeigniter中生成损坏的PDF,php,codeigniter,dompdf,Php,Codeigniter,Dompdf,我正在使用dompdf在codeigniter应用程序中生成pdf, 当我打开pdf时,它的给出错误 " 我检查了所有stackoverflow的资料 还有更多,但没有运气, 我的代码是: $html = file_get_contents(base_url() . "sampleHTMLfilepath"); require_once("dompdf/dompdf_config.inc.php"); if (is_null($this->_dompdf)) { $thi
$html = file_get_contents(base_url() . "sampleHTMLfilepath");
require_once("dompdf/dompdf_config.inc.php");
if (is_null($this->_dompdf)) {
$this->_dompdf = new DOMPDF();
}
$this->_dompdf->load_html($html);
$this->_dompdf->render();
$this->_dompdf->stream('test.pdf);
示例html是带有p标记的简单文件
<p>Hello </p>
你好
请帮帮我,
谢谢任何人都不应该对这个问题投反对票。无论如何,在控制器方法中尝试类似的方法,转换供您使用
// get some content
$data['order'] = $this->printmodel->getOrder();
// Load a view like you would normally do
$this->load->view('orderprint', $data);
// before going any further,
// make sure the content is showing on the view with no errors
// when you call the method
// all good? ok now add this part
// Get the output html
$html = $this->output->get_output();
// Load library
$this->load->library('dompdf_gen');
// Create pdf name based on date, hour, seconds
$pdfname = date("FjYgias");
// Convert to PDF
// (this is for streaming the pdf directly)
$this->dompdf->load_html($html);
$this->dompdf->render();
$this->dompdf->stream($pdfname);
这是一个比你要做的更复杂的例子-你不需要调用模型,等等-你可以调用视图
$this->load->view('somethingcooltoprint');
确认其工作正常,然后执行上述剩余代码。由于最后一行中缺少
”
,因此您的代码甚至不应运行。通常,在PDF源代码中插入PHP错误/通知会导致PDF损坏。如果启用了输出缓冲,则可能会发生这种情况。如果需要,请尝试在文本编辑器中打开PDF原因您可能会在PDF源代码之前看到PHP错误。