【问题标题】:Error in DOM PDF using Codeigniter使用 Codeigniter 在 DOM PDF 中出错
【发布时间】:2013-11-09 22:49:05
【问题描述】:

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

【问题讨论】:

  • 您遇到的服务器错误究竟是什么?
  • 类似“它可能因维护而停机或配置不正确”。
  • 查看服务器错误日志——他们应该会告诉你到底是什么问题。
  • 没有存储类似的东西
  • 你从哪里得到 dompdf?如果从 github 下载,请确保单击“发布”。我们推荐v0.6.0。如果您从主页单击“下载 ZIP”,您将成为 missing the required php-font-lib。除此之外,通过查看导致该消息的错误将有助于了解发生了什么。尝试在 index.php 中设置error_reporting(E_ALL)

标签: php codeigniter github dompdf


【解决方案1】:

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

删除 &lt;thead&gt;&lt;tbody&gt; 标记并删除 &lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt; 之间的空格

它会正常工作的。!

【讨论】:

    猜你喜欢
    • 2021-11-21
    • 1970-01-01
    • 1970-01-01
    • 2016-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多