PDF Generate using Laravel 6

pdf download

Hello Friends, Today I will teach how to Download PDF using Laravel 6.

Basically, PDF is using For Ecommerce, Financial and another firm for downloading for invoices and another thing.

So, Let’s Start our tutorial.


pdf output

Step 1: Install-Package of PDF.

Laravel will not provide PDF Download directly. So, We have to Install the package Composer in Laravel.

Open Your Terminal and put the below Code.

composer require barryvdh/laravel-dompdf

After Successfully install the package now move to the next step.

Step 2: Changes in Config File.

Now Open your config/app.php file and put the below code.

'providers' => [
'aliases' => [
  'PDF' => Barryvdh\DomPDF\Facade::class,

Step 3: Create a Route

Open web.php and put the below code.


Step 4: Changes in Controller.

Now create PDFController.php and put the below code

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use PDF;

class PDFController extends Controller{
    public function downloadpdf(){
        $data = ['name' => 'Dhaval Shah! How are you?'];
        $pdf_view = PDF::loadView('download-pdf', $data);
        return $pdf_view->download('download.pdf');

Step 5: Create a blade file.

Create a new blade file pdf.blade.php and put the below code.

<!DOCTYPE html>
    <h1>Laravel 6 Download PDF Tutorial</h1>
    <p>The Portable Document Format (PDF) (redundantly: PDF format) is a file format developed by Adobe in the 1990s to present documents, including text formatting and images, in a manner independent of application software, hardware, and operating systems.</p>

Now Open the browser and put the below code:


Keep Coding!

About Dhaval Shah

My name is Dhaval Shah. I'm a Laravel developer. I live in India and I love to write tutorials and tips that can help other developers. I am a big fan of PHP, Java-script, JQuery, Laravel, WordPress, and Bootstrap.
Follow me on Github / Linkedin

Leave a Reply

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

Subscribe To Our Newsletter
Enter your email to receive a weekly round-up of our best posts. Learn more!