2016-01-10 126 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的字符串路徑。