How to Make PDF File in Laravel 7?

How to Make PDF File in Laravel 7?

In this post we will give you information about How to Make PDF File in Laravel 7?. Hear we will give you detail about How to Make PDF File in Laravel 7?And how to use it also give you demo for it if it is necessary.

Today our leading topic is laravel 7 generate pdf file. i would like to show you how to generate pdf in laravel 7. you will learn laravel 7 create pdf from view. I’m going to show you about save as pdf in laravel 7.

As you know, few days ago laravel 7 released. so i plan to add tutorial for creating pdf file with laravel 7.

PDF is one of basic requirement when you are working with erp level project or e commerce website. we may need to create pdf file for report or invoice etc. So, here i will give you very simple example for create pdf file with laravel.

You need to just follow bellow step to create pdf file and also can download. So let’s do bellow steps.

Step 1: Install Laravel 7

I am going to explain step by step from scratch so, we need to get fresh Laravel 7 application using bellow command, So open your terminal OR command prompt and run bellow command:

composer create-project --prefer-dist laravel/laravel blog

Step 2: Install dompdf Package

first of all we will install barryvdh/laravel-dompdf composer package by following composer command in your laravel 7 application.

composer require barryvdh/laravel-dompdf

After successfully install package, open config/app.php file and add service provider and alias.


'providers' => [




'aliases' => [


'PDF' => BarryvdhDomPDFFacade::class,


Also see:Laravel 7 CRUD Example | Laravel 7 Tutorial For Beginners

Step 3: Add Route

In this is step we need to create routes for items listing. so open your “routes/web.php” file and add following route.



Step 4: Add Controller

Here,we require to create new controller PDFController that will manage generatePDF method of route. So let’s put bellow code.



namespace AppHttpControllers;

use IlluminateHttpRequest;

use PDF;

class PDFController extends Controller



* Display a listing of the resource.


* @return IlluminateHttpResponse


public function generatePDF()


$data = ['title' => 'Welcome to'];

$pdf = PDF::loadView('myPDF', $data);

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



Step 5: Create View File

In Last step, let’s create myPDF.blade.php(resources/views/myPDF.blade.php) for layout of pdf file and put following code:


Also see:Laravel 7 Auth Example | Laravel 7 Authentication Example

<!DOCTYPE html>






<h1>Welcome to - {{ $title }}</h1>

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod

tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,

quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo

consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse

cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non

proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>



Now we are ready to run this example and check it…

I hope it can help you…

Hope this code and post will helped you for implement How to Make PDF File in Laravel 7?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

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

  +  32  =  42

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US