0

我已经从 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 辅助函数

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

4

1 回答 1

0

在您的 home.php(视图)文件中,

移除<thead>and<tbody>标记并移除<html><head>,</head><body>和之间的空格</body></html>

它会正常工作的。!

于 2018-01-23T08:55:08.223 回答