Posted inTechnology / Laravel

Laravel 5.6 PDF Generation using Dompdf Example

Today, We want to share with you Laravel 5.6 PDF Generation using Dompdf Example.In this post we will show you PHP Laravel 5.6 PDF Generation using FPDF, hear for Best open source PDF generation libraries for Laravel 5.6 we will give you demo and example for implement.In this post, we will learn about Laravel 5.6 generate PDF from html view file and download using dompdf with an example.

Laravel 5.6 PDF Generation using Dompdf Example

There are the Following The simple About Laravel 5.6 PDF Generation using Dompdf Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop , so the some major files and Directory structures for this example is following below.

Laravel 5.6 PDF Generate Tutorial

  • Setup Laravel Project
  • Settings SQL Database
  • Setup Latest package in laravel-dompdf
  • Include Model and Migration File
  • Make a View File
  • Make one controller
  • Laravel 5.6 Route
  • Save All data to the database
  • Laravel 5.6 show the data.
  • Simple design Laravel 5.6 pdf blade file
  • Laravel 5.6 controller to simple download the PDF

Laravel 5.6 PDF Generation using Dompdf Tutorial With Example

I am Gonna to Configure step by step laravel 5.6 tutorial pdf Project.

Step #1: Setup Laravel 5.6 Project

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

Sytep #2: Settings SQL Database

setup database credentials >> .env file

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=topdevlopers
DB_USERNAME=atmiya25
DB_PASSWORD=Jaydeep@kji85

Step #3: Setup laravel-dompdf package

install The laravel-dompdf – laravel 5.6 tutorial pdf

composer require barryvdh/laravel-dompdf

Include Laravel 5.6 ServiceProviders in config/app.php

//laravel 5.6 tutorial pdf providers
'providers' => [
    ....
    Barryvdh\DomPDF\ServiceProvider::class,
],

Include Laravel 5.6 config/app.php

//some laravel 5.6 tutorial pdf aliases
'aliases' => [
    ....
    'PDF' => Barryvdh\DomPDF\Facade::class,
],

Step #4: Setup Laravel Model and Migration File

php artisan make:model TopDevloperInfo -m

Laravel Project Save as well as run.

php artisan migrate

Step #5: Make a Html View File

resources/views/topdevloperinfo.blade.php





  
    
    Laravel 5.6 PDF Generation using Dompdf Example
    
      
      
        
  
    

Laravel 5.6 PDF Generation using Dompdf Example


laravel 5.6 tutorial pdf

@csrf

Step #6: Make Laravel 5.6 controller

php artisan make:controller  TopDevloperInfoController

Create TopDevloperInfoController.php

//TopDevloperInfoController.php

public function create()
    {
        return view('topdevloperinfo');
    }

Step #7: Laravel 5.6 Route

Laravel 5.6 web.php file

Route::get('/topdevloperinfo','TopDevloperInfoController@create');
Route::post('/topdevloperinfo/store','TopDevloperInfoController@store');
Route::get('/topdevloperinfo/index','TopDevloperInfoController@index');
Route::get('/topdevloperinfo/downloadPDF/{id}','TopDevloperInfoController@downloadPDF');

Step #8: Save data to the Mysql database

TopDevloperInfoController.php

//TopDevloperInfoController.php

use App\TopDevloperInfo;

public function store(Request $request)
    {
        $devloper = new TopDevloperInfo();
        $devloper->name = $request->get('name');
        $devloper->language = $request->get('language');
        $devloper->position = $request->get('position');
        $devloper->devpoint = $request->get('devpoint');
        $devloper->save();
        return redirect('/topdevloperinfo/index');
    }

TopDevloperInfoController.php

//TopDevloperInfoController.php

public function index()
    {
        $devlopers = TopDevloperInfo::all();
        return view('index', compact('devlopers'));
      }

Step # 9: Make a HTML file for the Display the All data.

resources/views/index.blade.php




  
  laravel 5.6 tutorial pdf
    
    
  
  
      
@foreach($devlopers as $devloper) @endforeach
ID Name Language Position Dev Point Action
{{$devloper->id}} {{$devloper->name}} {{$devloper->language}} {{$devloper->position}} {{$devloper->devpoint}} PDF

Step #10: Make a HTML file to design Simple pdf blade

resources/views/pdf.blade.php





  
    
    Generate PDF from HTML in PHP Laravel 5.6 using Dompdf Library
  
  
    
{{$devloper->name}} {{$devloper->language}} {{$devloper->position}} {{$devloper->devpoint}}

Step #11: Laravel 5.6 function in the controller to PDF download

TopDevloperInfoController.php

//TopDevloperInfoController.php

name = $request->get('name');
        $devloper->language = $request->get('language');
        $devloper->position = $request->get('position');
        $devloper->devpoint = $request->get('devpoint');
        $devloper->save();
        return redirect('/topdevloperinfo/index');
    }

    public function index()
    {
        $devlopers = TopDevloperInfo::all();
        return view('index', compact('devlopers'));
      }

      public function downloadPDF($id)
      {
        $devloper = TopDevloperInfo::find($id);
        $pdf = PDF::loadView('pdf', compact('devloper'));
        return $pdf->download('topdevloperinfo.pdf');
      }
}
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about create Simple Generate PDF file in Laravel 5.6.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

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

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype