获取TCPDF:Some数据已经输出,无法在Laravel 4发送PDF文件
Getting TCPDF:Some data has already been output, can't send PDF file in Laravel 4
我正在使用 HTML2pDf 转换器生成 pdf 我的代码如下所示
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');
}
}
可能在流式传输 pdf 内容之前已经将某些内容写入输出缓冲区。
尝试使用 ob_end_clean() 在方法调用之前清理输出缓冲区:
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');
我正在使用 HTML2pDf 转换器生成 pdf 我的代码如下所示
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');
}
}
可能在流式传输 pdf 内容之前已经将某些内容写入输出缓冲区。
尝试使用 ob_end_clean() 在方法调用之前清理输出缓冲区:
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');