2017-07-18 102 views
0

任何人都可以幫助我,我試圖在codeigniter中使用dompdf庫。當我在本地做它的工作。但是當我的網站上傳時,它不能正常工作。這裏的庫代碼在codeigniter中使用dompdf庫

<?php defined('BASEPATH') OR exit('No direct script access allowed'); 
/** 
* CodeIgniter PDF Library 
* 
* Generate PDF's in your CodeIgniter applications. 
* 
* @package   CodeIgniter 
* @subpackage  Libraries 
* @category  Libraries 
* @author   Chris Harvey 
* @license   MIT License 
* @link   https://github.com/chrisnharvey/CodeIgniter-PDF-Generator-Library 
*/ 
require_once(dirname(__FILE__) . '/dompdf-0.6.2/dompdf_config.inc.php'); 
class Pdf extends DOMPDF 
{ 
    /** 
    * Get an instance of CodeIgniter 
    * 
    * @access protected 
    * @return void 
    */ 
    protected function ci() 
    { 
     return get_instance(); 
    } 
    /** 
    * Load a CodeIgniter view into domPDF 
    * 
    * @access public 
    * @param string $view The view to load 
    * @param array $data The view data 
    * @return void 
    */ 
    public function load_view($view, $data = array()) 
    { 
     $html = $this->ci()->load->view($view, $data, TRUE); 
     $this->load_html($html); 
    } 
} 

此代碼來調用創建PDF,我儘量只調用視圖和它的工作,但其時名爲「PDF」功能,屏幕是空白。

$this->load->library('pdf'); 
    $this->pdf->load_view('mydocument', $data); 
    $this->pdf->render(); 
    $this->pdf->stream("mydocument.pdf"); 

,這是我的文件

enter image description here

+0

你是怎麼調用這個文件的?我們沒有足夠的信息能夠回答這個問題 – Nick

+0

對不起,我忘了把代碼,我現在編輯問題現在 –

+0

另外,它是如何「不工作」。有沒有錯誤?有沒有任何截圖是相關的。 – Nick

回答

0

正如評論指出@ jagad89是正確的關於包括DOMPDF自動加載文件結構。

而不是使用其與庫包裝,儘量與作曲家安裝

composer require dompdf/dompdf 

然後設置的$config['composer_autoload'] = '/path/to/vendor/autoload.php';在應用程序的config.php,你要善於使用DOMPDF這樣的:

$dompdf = new Dompdf\Dompdf(); 
$dompdf->loadHtml('hello world'); 

// Render the HTML as PDF 
$dompdf->render(); 
$dompdf->stream(); 
0

反過來在控制器中使用下面的代碼,它應該爲你工作。

$this->load->library('pdf'); 
$this->pdf->load_view('mydocument', $data); 
$this->pdf->setPaper('A4', 'portrait'); 
$this->pdf->render(); 
$this->pdf->stream("mydocument", array("Attachment" => 0));