clock  Mon - Sun 8.00 AM - 8.00 PM
play store

How to download pdf file using Laravel 8 dompdf

writter  Hariom Prajapati
Date  26 Jun 2022
Language  Laravel
How to download pdf file using Laravel 8 dompdf

How to download pdf file using Laravel 8 dompdf

Normally, when we work on large project on laravel then we require to generate PDF file of database table. So, In this tutorial we will learn about Laravel pdf package ( laravel dompdf ) using which we can download pdf file .

Here, we use laravel dompdf for create pdf and this package also provide the function of download. 

Now follow all the below steps to download pdf using laravel 8 .


Step 1 – In first step , Install dompdf package 

Run this command in your cmd terminal –

composer require barryvdh/laravel-dompdf

how to download pdf using laravel 8 dompdf


Step 2 - In second step open config/app.php file and update package service provider and alias.

    'providers' => [

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




Step 3 – Create Controller

php artisan make:controller PdfController



namespace App\Http\Controllers;
Use PDF;
use Illuminate\Http\Request;

class PdfController extends Controller
    public function downloadPDF(){
        $data = [
           "full_name"=> "john do",
           "email"=> "",
        $pdf = PDF::loadView('Sample_pdf',$data);
        return $pdf->download('teknowize.pdf');



Step 4- Create Route

use App\Http\Controllers\PdfController;
use Illuminate\Support\Facades\Route; 

| Web Routes

Route::get('download-pdf', [PdfController::class, 'downloadPDF']); 



Step 5 –  Create pdf view template 

In this step , Create Sample_pdf.blade.php in resources\views .


<!DOCTYPE html>

        table tr th {
            background-color: #04AA6D;
            color: white;
            border: 1px solid #ddd;
            padding: 8px;

        table tr td {
            border: 1px solid #ddd;
            padding: 8px;

    <h3>Laravel 8 PDF Example Using dompdf </h3>
            <th>Full Name</th>
            <th>Email Id</th>
            <th>Phone Number</th>
            <td>{{ $full_name }}</td>
            <td>{{ $email }}</td>
            <td>{{ $age }}</td>
            <td>{{ $phone }}</td>




Step 6 – Run php artisan serve

php artisan serve


Finally , run this url in your browser