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.

Installation:

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.

Barryvdh\DomPDF\ServiceProvider::class,

 

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

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

 

Example:

$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  : https://github.com/barryvdh/laravel-dompdf

Leave a Comment

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

Scroll to Top