How to generate PDF from html view file in laravel? the rich post

Laravel 7.2 routing with route group auth guard check with prefix

generate PDF from html view file in laravel

Hello to all, welcome to In this post, I will tell you, How to generate PDF from html view file in laravel?

Here are the following steps to generate PDF from html view file in laravel? the rich post:
1.  Need to install laravel-dompdf package with below command:
composer require barryvdh/laravel-dompdf
2. After installing laravel-dompdf package you need to set their service provider and alias in following path config/app.php.
'providers' => [

'aliases' => [
    'PDF' => Barryvdh\DomPDF\Facade::class,
 3. Set Up blade view template for resources/view/htmltopdfview.blade.php:
<div class="row">
    <a href="{{ route('htmltopdfview',['download'=>'pdf']) }}">Download PDF</a>
        @foreach ($products as $product)
            <td>{{ $product->name }}</td>
            <td>{{ $product->details }}</td>
 4. Set up the app/Http/Controllers/ProductController.php.
namespace App\Http\Controllers;
use App\Http\Requests;
use Illuminate\Http\Request;
use App\Product as Product;
use PDF;
class ProductController extends Controller
    public function htmltopdfview(Request $request)
        $products = Products::all();
            $pdf = PDF::loadView('htmltopdfview');
            return $pdf->download('htmltopdfview');
        return view('htmltopdfview');
 5. Set up the laravel routes/web.php.

 Now you are done. If you have any query related to this post, then feel free to ask.


Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, Angular 8, Angular 9, Angular 10, Angular 11, Nodejs, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.