2016-01-10 74 views
0

我在使Codeigniter mPDF库正常工作时遇到了一些麻烦。下面是“应用程序/库”类:Codeigniter mPDF库无法加载

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

下面是错误:

Fatal error: require_once(): Failed opening required 'X:/xampp/htdocs/.../application/third_party/m_pdf/config_cp.php' (include_path='.;X:\xampp\php\PEAR') in X:\xampp\htdocs...\application\third_party\m_pdf\mpdf.php on line 39

Kindly assist

+0

而不是包括尝试这个 require_once APPPATH。 “THIRD_PARTY/m_pdf/mpdf.php”; $ mpdf = new mPDF('c','A4'); –

+0

嗨,require_once仍然会抛出相同的错误 – Kabs

回答

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的字符串路径。