使用Codeigniter在DOM PDF中出错

时间:2013-10-30 11:28:33

标签: php codeigniter github dompdf

我从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文件。任何人都可以帮助这个

1 个答案:

答案 0 :(得分:0)

在home.php(查看)文件中,

删除<thead><tbody>代码,并删除<html><head></head><body></body></html>

之间的空格

一切正常。!