Laravel PHP

Generate a PDF in Laravel

Hello, today we are talking about generating PDF. In Laravel generating PDF is pretty easy and simple. There are lots of libraries which is used to generate a PDF, but I think one of the best library for generating PDF is ‘laravel-dompdf’. It’s easy to install and configure. You can use chain methods, change paper size and many more configuration options available here.


Add following line in your ‘composer.json’ file.

composer require barryvdh/laravel-dompdf


After updating composer add following line to your config/app.php file.



If you want to use shorter façade, then add following line to your façade. Its optional.

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



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


Using Façade.

$pdf = PDF::loadView('pdf.invoice', $data);return $pdf->download('invoice.pdf');


Link  :

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.