我从github https://github.com/EllisLab/CodeIgniter/wiki/PDF-generation-using-dompdf
下载了dompdf库控制器功能
function pdf()
{
$this->load->helper('dompdf');
// page info here, db calls, etc.
$this->data['query'] = $this->my_model->dashboard_db();
$this->data['queryCmt'] = $this->my_model->dashboard_comment_task_db();
$html = $this->load->view('home',$this->data, true);
$fn = 'file_pdf';
$data = pdf_create($html, $fn, true);
write_file($fn, $data);
//if you want to write it to disk and/or send it as an attachment
}
Dom pdf Helper功能
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
function pdf_create($html, $filename, $stream=TRUE)
{
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
if ($stream) {
$dompdf->stream($filename.".pdf");
} else {
return $dompdf->output();
}
}
?>
这给了我一个服务器错误,但如果我在控制器中删除pdf_create()生成一个pdf文件。任何人都可以帮助这个
答案 0 :(得分:0)
在home.php(查看)文件中,
删除<thead>
和<tbody>
代码,并删除<html><head>
,</head><body>
和</body></html>
一切正常。!