Codeigniter mPDF库无法加载

时间:2016-01-10 07:04:54

标签: php codeigniter mpdf

我在使用Codeigniter mPDF库时遇到一些麻烦。以下是' application / libraries'中的课程:

class mpdf {

    function mpdf() {
        $CI = & get_instance();
        log_message('Debug', 'mPDF class is loaded.');
    }

    function load($param = NULL) {
        include_once APPPATH . 'third_party/m_pdf/mpdf.php';

        if ($params == NULL) {
            $param = '"en-GB-x","A4","","",10,10,10,10,6,3';
        }

        return new mPDF($param);
    }

}

虽然我打算输出pdf的函数如下:

//pdf
    public function outputPDF() {
        //this data will be passed on to the view
        $data['the_content'] = 'mPDF and CodeIgniter are cool!';

        //load the view, pass the variable and do not show it but "save" the output into $html variable
        $html = $this->load->view('pdf_output', $data, true);

        //this the the PDF filename that user will get to download
        $pdfFilePath = "the_pdf_output.pdf";

        //load mPDF library
        $this->load->library('mpdf');
        //actually, you can pass mPDF parameter on this load() function
        $pdf = $this->mpdf->load();
        //generate the PDF!
        $pdf->WriteHTML($html);
        //offer it to user via browser download! (The PDF won't be saved on your server HDD)
        $pdf->Output($pdfFilePath, "D");
    }

以下是错误:

  

致命错误:require_once():无法打开所需的错误   ' X:/ XAMPP / htdocs中/.../应用/ THIRD_PARTY / m_pdf / config_cp.php'   (include_path =' .; X:\ xampp \ php \ PEAR')in   第39行的X:\ xampp \ htdocs ... \ application \ third_party \ m_pdf \ mpdf.php

请帮助

1 个答案:

答案 0 :(得分:0)

我在库中遇到了同样的问题。现在我开始使用我的CodeIgniter应用程序了。

为了使其工作,我不得不将库文件夹放在third_party文件夹中(在应用程序文件夹内)。然后我做了一个自动加载器。在库文件夹中,我创建了一个名为Pdf.php的文件

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Pdf {

    function Pdf()
    {
        $CI = & get_instance();
        log_message('Debug', 'mPDF class is loaded.');
    }

    function load($param=NULL)
    {
        include_once APPPATH.'third_party/mpdf/mpdf.php';

        if ($params == NULL)
        {
            $param = '"en-GB-x","A4","","",10,10,10,10,6,3';         
        }

        return new mPDF($param);
    }
}

然后,您可以像CodeIgniter所期望的那样加载库:

$this->load->library('pdf');
$pdf = $this->pdf->load();
$pdf->SetFooter($_SERVER['HTTP_HOST'].'|{PAGENO}|'.date(DATE_RFC822)); // Add a footer
$pdf->WriteHTML($html); // write the HTML into the PDF
$pdf->Output($pdfFilePath, 'F'); 

$ html是包含要导出的html视图的字符串。 $ pdfFilePath是我们保存pdf的字符串路径。