[英]Getting TCPDF:Some data has already been output, can't send PDF file in Laravel 4
I am using HTML2pDf convertor to generate pdf my code looks like this我正在使用 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');
I am getting following error我收到以下错误
TCPDF ERROR: Some data has already been output, can't send PDF file
TCPDF ERROR:部分数据已经输出,无法发送PDF文件
The function where I have this script looks like this我有这个脚本的函数看起来像这样
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');
}
}
Probably something has already been written to the output buffer prior to streaming the pdf content.在流式传输 pdf 内容之前,可能已经将某些内容写入输出缓冲区。
Try to use ob_end_clean() to clean the output buffer just before the method invocation:尝试使用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');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.