Search code examples
laraveldompdf

How to show white paper (data) pdf file before download this file


I have a function to show PDF . its triggered by click button to show/download pdf .

this function can show/displayed this data (before download) if i using php artisan serve , but now i not using php artisan serve because of BUG on my datatables , so i using XAMPP .

if i clicking button to download ,its not displaying data, its download automaticly .

how i can solved this ?

public function PDF(Request $request,$id){
    $users = User::findOrFail($id);

    $pdf = PDF::loadView('admin.pdf',['users' => $users]);
    return $pdf->stream('Profile.pdf', array('Attachment'=>0));              
}

its my controller


Solution

  • Please mention header

    $pdf->stream('Profile.pdf')
               ->header('Content-Type','application/pdf');
    

    Please check your carome setting as well.

    1) On your computer, open Chrome.

    2) At the top right, click More Settings.

    3) At the bottom, click Advanced.

    4) Under "Privacy and security," click Site settings.

    5) Near the bottom, click PDF documents.

    6) Turn on Download PDF files instead of automatically opening them in Chrome.