Generating a PDF using CodeIgniter

可紊 提交于 2019-12-11 01:28:13

问题


I am using dompdf to create a pdf file out of an html file that gets created on-the-fly for the sole purpose of it serving as input for the pdf generator, however I am having trouble doing this, I implemented the code in this thread and everything works fine (I could output a simple pdf) however when I try to give it a more specific url I get this error:

An Error Was Encountered Unable to load the requested file

here's the code that has the problem:

function printPDF(){

            //write_file() usa un helper (file)
            $this->load->library('table');
            $this->load->plugin('to_pdf');
             // page info here, db calls, etc.
             $query = $this->db->get('producto');
             $data['table'] = $this->table->generate($query);
             $path_url = base_url().'print/existencias.html';
             write_file($path_url, $data['table']);
             $html = $this->load->view($path_url, 'consulta', true);
             pdf_create($html, 'consulta');
        }

回答1:


Not sure about the exact problem, but please check this:

1) as stated in CI's manual, load->view's second parameter should be an associative array or an objet, translated to vars via extract. That may generate some problem generating $html.

2) try making $path_url relative to application/views directory, as read in CI's manual.




回答2:


you should use tcpdf to create a pdf. //create controller for example :

public function create_pdf() 
    {
     $this->load->library("Pdf");
     $data['results'] = // your data
     $this->load->view('pdfview',$data);

    }


//pdfview is the page having tcpdf code and your pdf code.


来源:https://stackoverflow.com/questions/5035112/generating-a-pdf-using-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!