2012-09-26 47 views
1

我將使用FPDF庫生成PDF報告,但輸出爲空。沒有顯示錯誤,我該如何解決這個問題?使用FPDF庫的空白輸出PDF - codeigniter

不管怎樣,我想在這LOCALHOST代碼,它完美的作品,但是當我把它上傳到雲中,沒有輸出顯示。我試圖讓函數輸出這樣的..

$this->fpdf->OUTPUT('try.pdf','I'); but nothing happens.. 

注意:在我的輸出中,C:/ backup/employee _ .. php,輸出在文件夾中,沒有錯誤,並且工作正常..但是當我上傳這一個時,沒有要顯示的輸出

這是我的控制器:

public function backup_employees_pdf() 
{ 

    $this->load->library('fpdf'); 

    define('FPDF_FONTPATH',$this->config->item('fonts_path')); 
    $this->fpdf =new FPDF('L', 'mm', 'Legal', true, 'UTF-8', false); 
    $this->fpdf->AliasNbPages(); 
    $this->fpdf->AddPage(); 

    //load data 
    $data = array(); 
    $row = $this->m_employee->load_data_employees(); 
    $data = $row->result(); 

    // Whatever written here will come in header of the pdf file. 

    $this->fpdf->Image('assets/images1/mpowerstafflogo.jpg',10,5,50,50,'','www.mpowerstaff.com'); 
    $this->fpdf->SetFont('Arial','B',15); 
    $this->fpdf->Cell(140); 
    $this->fpdf->Cell(50,10,'Employee File Management Website',0,0,'C'); 
    $this->fpdf->Ln(5); 
    $this->fpdf->Cell(140); 
    $this->fpdf->Ln(5); 
    $this->fpdf->SetFont('Arial','',12); 
    $this->fpdf->Cell(140); 
    $this->fpdf->Cell(50,10,'3F Room 305 Jackson Bldg. 926 Arnaiz Ave., San Loreno Village Makati City, 1223 PHILIPPINES',0,0,'C'); 
    $this->fpdf->Ln(5);  
    $this->fpdf->Ln(5); 
    $this->fpdf->Cell(140); 
    $this->fpdf->Cell(50,10,'Tel. (632) 810-4026 * 810-9121',0,0,'C'); 
    $this->fpdf->Ln(5); 
    $this->fpdf->Ln(5); 
    $this->fpdf->Cell(140); 
    $this->fpdf->Cell(50,10,'Email: [email protected]',0,0,'C'); 
    $this->fpdf->Ln(10); 
    $this->fpdf->SetFont('Arial','B',12); 
    $this->fpdf->Cell(140); 
    $this->fpdf->Cell(50,10,'Employees Report',0,0,'C'); 
    $this->fpdf->Ln(15); 

    // Colors, line width and bold font 
    $this->fpdf->SetFillColor(105,100,231); 
    $this->fpdf->SetTextColor(255); 
    $this->fpdf->SetDrawColor(60,89,117); 
    $this->fpdf->SetLineWidth(0.3); 
    $this->fpdf->SetFont('', 'B'); 

    // Header 
    $w = array(35,80,40,40,40,40,61); 

    $this->fpdf->Ln(); 

    //border LRTB 
    $this->fpdf->Cell(5); 
    $this->fpdf->Cell(90,10,'NAME',1,0,'C', 'LR'); 
    $this->fpdf->Cell(60,10,'ACCOUNT NUMBER',1,0,'C', 'LR'); 
    $this->fpdf->Cell(60,10,'ADDRESS',1,0,'C', 'LR'); 
    $this->fpdf->Cell(60,10,'BIRTHDAY',1,0,'C', 'LR'); 
    $this->fpdf->Cell(60,10,'CONTACT NO.',1,0,'C', 'LR'); 
    $this->fpdf->Ln(10); 

    // Color and font restoration 
    $this->fpdf->SetFillColor(224, 235, 255); 
    $this->fpdf->SetTextColor(0); 
    $this->fpdf->SetFont(''); 

    $fill = 0; 
    //data 
    foreach($data as $empsItem) 
    {  
     $this->fpdf->Cell(5); 
     $this->fpdf->Cell(90,10,$empsItem->name,1,0,'C',$fill); 
     $this->fpdf->Cell(60,10,$empsItem->account_no,1,0,'C',$fill); 
     $this->fpdf->Cell(60,10,$empsItem->address,1,0,'C',$fill); 
     $this->fpdf->Cell(60,10,$empsItem->birthday,1,0,'C',$fill); 
     $this->fpdf->Cell(60,10,$empsItem->contact_no,1,0,'C',$fill); 
     $this->fpdf->Ln(10); 
     $fill=!$fill; 
    } 

    $this->fpdf->Ln(30); 
    $this->fpdf->SetFont('Arial','B',10); 
    $this->fpdf->Cell(20, 5,'Total Employees: '.$row->num_rows(), '', 0, 'LR', 0); 

    $this->fpdf->SetY(184); 
    $this->fpdf->SetFont('Arial','I',8); 
    $this->fpdf->Cell(0,10,'Copyright. All Rights Reserved',0,0,'C'); 
    $this->fpdf->Cell(0,10,'Page '.$this->fpdf->PageNo().' of {nb}',0,0,'C'); 

    $dir = 'C:/backup/'; 
    $filename = "employee report"; 

    $this->fpdf->Output($dir.$filename.'.pdf'); 
} 

// ==== THIS IS MY模型=== //

public function load_data_employees() 
{ 
    $query = $this->db->query("SELECT concat(e_first_name,' ',e_middle_name,' ',e_last_name) AS 'name',account_number AS 'account_no',address AS 'address',birthday AS 'birthday',contact_number AS 'contact_no'FROM tb_emp where status='available'"); 
    return $query; 
} 

// == == CONFIG.PHP //

$config['fonts_path']= "./system/fonts/font/"; 

這就是細節。我試圖解決這個問題,但仍然沒有輸出。

+0

幾個問題:1)具有該代碼永遠遠程工作,或者這是第一次測試? 2)PHP /它運行的用戶是否可以訪問輸出目錄? – user1201210

+0

是的..它的工作原理! 是的..它遠程工作,我允許用戶的文件夾有一個訪問寫..順便說一句..在我運行它之前,我已經試過這個: $ this-> fpdf - >輸出( 'file.pdf', 'I');它的工作,但我嘗試上傳它,那裏沒有輸出。 – watangka

+0

嘗試使用mpdf它容易在codeigniter中使用 –

回答

0

我有同樣的問題,這是我的解決方案:

而不是使用

$this->fpdf =new FPDF() 

我用

$pdf = new FPDF(); 

然後u可以使用$ PDF - > ...和不是$ this-> pdf - > ...

這裏是一個例子:

define('FPDF_FONTPATH',$this->config->item('fonts_path')); 
$this->load->library(array('fpdf','fpdf_rotate','pdf')); 
$this->pdf->Open(); 
$pdf = new PDF(); 
$pdf->AliasNbPages(); 
$pdf->AddPage(); 
$pdf->SetFont('Arial', '', 12); 
$pdf->SetDrawColor(0); 
$pdf->MultiCell(100,5,"Test\n line of text"); 
$pdf->Output('test.pdf', 'D'); 

就像一個魅力;)

+0

你能解釋爲什麼這可能解決這個問題嗎? – Goose