在浏览器中指向白页而不是在laravel-dompdf中下载PDF

问题描述 投票:0回答:1

我在laravel-dompdf中遇到了问题。我认为我的代码是正确的,我不知道为什么它指向白页而不是下载pdf。它在其他控制器中工作,但这不是。

white page

我控制器中的代码:

public function export_pdf()
{
    if(Auth::user()->campus_id == 0){
        $processes = Process::join('bags','processes.bag_id', '=', 'bags.id')
              ->join('stations','processes.station_id', '=', 'stations.id')
              ->select('bags.*','stations.*','processes.*')
              ->where('stations.campus_id', Session::get('test'))
              ->orderBy('processes.id', 'desc')
              ->get();


        // Send data to the view using loadView function of PDF facade
        $pdf = PDF::loadView('collectionReportspdf', compact('processes'));
        // If you want to store the generated pdf to the server then you can use the store function
        $pdf->save(storage_path().'_filename.pdf');
        // Finally, you can download the file using download function
        return $pdf->download('reports.pdf');
   }
   else{
       $processes = Process::join('bags','processes.bag_id', '=', 'bags.id')
              ->join('stations','processes.station_id', '=', 'stations.id')
              ->select('bags.*','stations.*','processes.*')
              ->where('stations.campus_id', Auth::user()->campus_id)
              ->orderBy('processes.id', 'desc')
              ->get();


       // Send data to the view using loadView function of PDF facade
       $pdf = PDF::loadView('collectionReportspdf', compact('processes'));
       // If you want to store the generated pdf to the server then you can use the store function
       $pdf->save(storage_path().'_filename.pdf');
       // Finally, you can download the file using download function
       return $pdf->download('reports.pdf');
   }

}
dompdf laravel-5.7
1个回答
0
投票

在过去,我必须在保存或输出到浏览器之前渲染PDF。

尝试在$pdf->save()上面添加以下内容:

$pdf->render();

如果它仍然不起作用,请尝试用return替换echo语句。

© www.soinside.com 2019 - 2024. All rights reserved.