Generate PDF File Using DomPDF laravel 9

In this tutorial, we will see laravel 9 generate pdf file using dompdf. for generating pdf file and viewer.

In this series of articles, we have covered about:
Web Application Model Data Model Data Processing Data Storage. Generate PDF File Using DomPDF laravel 9. Documentation for Laravel and django. Please note that these articles are aimed towards absolute beginners and are not really appropriate for advanced developers. If you have any doubt, feel free to drop in a comment and I’ll be happy to discuss it with you!
And that’s all for today!

 Step 1 : Install Laravel 9 of Generate PDF File Using DomPDF laravel 9

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

Step 2 : Installing barryvdh/laravel-dompdf Package

composer require barryvdh/laravel-dompdf

Step 3 : Create Controller

i am happy for contoller created done so i can pdfcontoller.php


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;
use PDF;

class pdfcontoller extends Controller
    public function index(Request $request)
	    $user = Blog::get();

	    $data = [
	            'maintitle' => 'Laravel 9 Generate PDF File Using DomPDF - laratuto',
	            'maindate' => date('d/m/Y'),
	            'activeusers' => $users

	        $pdf = PDF::loadView('index',$data);
	        return $pdf->download('pdfview.pdf');

	    return view('index',compact('user'));

Step 5 : Add Route

After add route in api.php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\pdfcontoller;
Route::resource('users', pdfcontoller::class);

Step 6 : Create Blade File

<!DOCTYPE html>
  <title>Laravel 9 Generate PDF File Using DomPDF - laratuto</title>
  <link rel="stylesheet" href="">
  <script src=""></script>
  <div class="container">
    <div class="row">
      <div class="col-lg-12" style="margin-top: 15px ">
        <div class="pull-left">
        <div class="pull-right">
          <a class="btn btn-primary" href="{{route('users.index',['download'=>'pdf'])}}">Download PDF Now</a>
    <table class="table table-bordered">
        <th>User Name</th>
        <th>User Email</th>
      @foreach ($user as $user)
        <td>{{ $user->mainname}}</td>
        <td>{{ $user->mainemail}}</td>

I happy if this project run or pdf download done..

Please find your questions and my answers to your questions at the next link below:
Got an idea for a new CMS/AJAX project? Maybe you would like to develop a blog engine or mobile application? Do you have some tips and tricks you would like to share with the PHP community? Or maybe you would like to talk to other aspiring PHP developers about their projects? If so, feel free to contact me!
Pragmatic Collaboration PHP Network is a new