2015-12-17 35 views
0

我使用HTML2PDF轉換生成PDF我的代碼看起來像這樣獲得TCPDF:一些數據已輸出,不能發送PDF文件中Laravel 4

require_once(app_path().'/libs/html2pdf/html2pdf.class.php') ; 
    $html2pdf = new HTML2PDF('P','A4','en',true,'UTF-8',array(0, 0, 0, 0)); 
    $html2pdf->pdf->SetDisplayMode('fullpage'); 
    $html2pdf->WriteHTML($html22); 
    $html2pdf->Output($username.'_questionnaire.pdf'); 

我收到以下錯誤

TCPDF ERROR: Some data has already been output, can't send PDF file

在那裏我有這個腳本看起來功能類似這樣的

public function postExporttopdf(){ 
     $validator = Validator::make(Input::all(),array('delid'=>'required')); 
     $event = Session::get('tempevenname'); 
     if($validator->passes()){ 

      $uid1 = Input::get('delid'); 
      $username = User::find(Input::get('delid'))->name; 

      $page1data = Question::where('event','=',$event)->where('page','=',1)->orderBy('order')->with('choices') 
      ->with(array('answers'=>function($query){ 
        $query->where('user_id','=',Input::get('delid')); 
      }))->get(); 

      $page2data = Question::where('event','=',$event)->where('page','=',2)->orderBy('order')->with('choices') 
      ->with(array('answers'=>function($query){ 
        $query->where('user_id','=',Input::get('delid')); 
      }))->get(); 

      $page3data = Question::where('event','=',$event)->where('page','=',3)->orderBy('order')->with('choices') 
      ->with(array('answers'=>function($query){ 
        $query->where('user_id','=',Input::get('delid')); 
      }))->get(); 

      $page4data = Question::where('event','=',$event)->where('page','=',4)->orderBy('order')->with('choices') 
      ->with(array('answers'=>function($query){ 
        $query->where('user_id','=',Input::get('delid')); 
      }))->get(); 

       $html22 = View::make('reviewsendpdf')->with(array(

            'page1data'=>$page1data, 

            'page2data'=>$page2data, 

            'page3data'=>$page3data, 

            'page4data'=>$page4data 

            )); 



      require_once(app_path().'/libs/html2pdf/html2pdf.class.php') ; 
      $html2pdf = new HTML2PDF('P','A4','en',true,'UTF-8',array(0, 0, 0, 0)); 
      $html2pdf->pdf->SetDisplayMode('fullpage'); 
      $html2pdf->WriteHTML($html22); 
      $html2pdf->Output($username.'_questionnaire.pdf'); 

     } else { 
      return Redirect::to('admin/exporttopdf')->with('message','Select a user and event'); 
     } 
    } 
+1

可能是你的腳本發送一些數據,在此之前的代碼執行;請在這段代碼中使用代碼部分 – Moppo

+0

@Moppo好的我正在更新函數 – Vikram

+0

如果庫在其他控制器操作中運行良好,您是否嘗試過?例如將一些虛擬測試數據傳遞給庫而不是這個視圖? – Moppo

回答

1

可能是一些已經被寫入輸出緩衝區流PDF內容

嘗試使用ob_end_clean只是方法調用之前清理outpput緩衝區之前d:

require_once(app_path().'/libs/html2pdf/html2pdf.class.php') ; 
$html2pdf = new HTML2PDF('P','A4','en',true,'UTF-8',array(0, 0, 0, 0)); 
$html2pdf->pdf->SetDisplayMode('fullpage'); 
$html2pdf->WriteHTML($html22); 

ob_end_clean(); 

$html2pdf->Output($username.'_questionnaire.pdf'); 
相關問題