Generate PDF from Html in Laravel

In this tutorial, I am going to explain “How to create PDF from html in Laravel” by using laravel dompdf package.

There are lots of pdf packages that are using to generate pdf from html with  CSS, you can easily set the beautiful layout for pdf file using css most of the packages support css in pdf.

Using laravel-dompdf library, you can easily generate pdf file in your Laravel web application.

When you are need to sending report in email from large amount of data then you can convert your html view in pdf file and attach that file with mail or if we work on big ERP level project on laravel, we require to generate PDF file for data from database table.

In this tutorials we are using on of the best package barryvdh/laravel-dompdf it provide very easy way to generate html to pdf in laravel.

We are explain all code step by step:-

Step 1:- First need to install dompdf package in our laravel application using following command.




Step 2:- After install DOM PDF package for laravel we must be configure, So just open your config/app.php file and set following value for providers array and aliases array

Step 3:- In this step we need to set route for generate view.  So just open your app/Http/routes.php file and add following route.

 

Step 4:- Now we should create  controller as DemoController in this path app/Http/Controllers/DemoController.php

This controller will manage data and generate pdf file, so put bellow content in controller file

Step 5:- In last step, we have to create view file “pdf_view.blade.php” for generate view and also pdf file, so create pdf_view file and put bellow code:

View Demo
 

I hope you might have understood it properly, keep reading our other blog posts for more coding tricks.

Thanks!!

One Comment

Add a Comment

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