Laravel 5.1 - barryvdh/laravel-dompdf, PDF file download not working properly

后端 未结 3 625
抹茶落季
抹茶落季 2021-01-05 12:12

I have installed \'barryvdh/laravel-dompdf\' using composer and added these lines

Barryvdh\\DomPDF\\ServiceProvider::class
\'PDF\'=>  Barryvdh\\DomPDF\\F         


        
相关标签:
3条回答
  • 2021-01-05 12:52

    What do you want to do with pdf ? To show in browser or to download to disc? this is example where pdf is downloaded

    return $pdf->download('pdfName.pdf'); 
    

    example from my code where i show notebook information in pdf

       $laptop = Notebook::findOrFail($id);
            $data['laptop'] = $laptop;
            $pdf = \PDF::loadView('pdf.detaljiLaptop', $data);
    
            return $pdf->download($laptop->modelName.' Computers.pdf'); 
    
    0 讨论(0)
  • 2021-01-05 12:54

    I use this code view()->share($data); $pdf = PDF::loadview('sale.pdf'); return $pdf->download('slip_out.pdf');

    instead of

    return $pdf->stream('testfile.pdf')
                   ->header('Content-Type','application/pdf');
    
    0 讨论(0)
  • 2021-01-05 12:59

    I had the same problem, after searching all over without results, I decided to play with the code and this worked for me.

    Inside config/app.php

    -> under providers add the line of code,

    'Barryvdh\DomPDF\ServiceProvider' not Barryvdh\DomPDF\ServiceProvider::class,
    

    -> under aliases add the line of code,

    'PDF'       => 'Barryvdh\DomPDF\Facade' not 'PDF' => Barryvdh\DomPDF\Facade::class,
    

    Mind the quotes and commas! Check the images above,

    -> In your controller add the line of code, use App;

    Hopefully, you will be good to go....test using the lines of code..place them inside a method in your controller.

    $pdf = App::make('dompdf.wrapper');
    $pdf->loadHTML('<h1>Test</h1>');
    return $pdf->stream();
    

    On success, your browser will open a PDF Viewer with a white PDF with the word Test

    Cheers, enjoy your coding ;)

    0 讨论(0)
提交回复
热议问题