开发者

Generating a PDF using CodeIgniter

开发者 https://www.devze.com 2023-02-11 23:49 出处:网络
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 imp

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');
        }


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.


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.


You can try it like this

public function export_pdf() {
    $filename = 'FILENAME.pdf';
    header("Content-Description: Advertise Report");
    header("Content-Disposition: attachment; filename=$filename");
    header("Content-Type: application/pdf; ");
    $file = fopen('php://output', 'w');
    $header = array("Question", "Answer", "Name", "Email", "Phone", "Date");
    fputpdf($file, $header);
    fputpdf($file, 'YOUR DATA');
    fclose($file);
    exit;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消