dongli1920 2015-12-07 08:01
浏览 51
已采纳

dompdf在codeigniter中生成损坏的pdf

I am using dompdf for generating pdf in codeigniter application, When I am opening pdf its giving error

enter image description here"

I checked all stackoverflow stuffs for this,

and more,but no luck, my code is :

$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);

sample html is simple file with p tag

<p>Hello </p>

Please help me, Thanks

  • 写回答

1条回答 默认 最新

  • duanmianxue2687 2015-12-07 20:03
    关注

    no one should be down voting this question. anyway try something like this in your controller method, convert for your use.

    // 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);
    

    and this is a much more complicated example then what you are trying to do - you don't have to call a model, etc - you can just call the view,

    $this->load->view('somethingcooltoprint');
    

    confirm its working and then do the rest of the code like above.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。