Laravel 7 Generate PDF with Graph

In this tutorial you will learn about the Laravel 7 Generate PDF with Graph and its application with practical example.

In this Laravel 7 Generate PDF with Graph tutorial, I’ll show you how to generate pdf with graph in laravel. In this tutorial you will learn to generate pdf file with graph in laravel.

Laravel 7 Generate PDF with Graph

  • Step 1: Install wkhtmltopdf Software
  • Step 2: Download Laravel Fresh App
  • Step 3: Install mikehaertl/phpwkhtmltopdf
  • Step 4: Add Routes
  • Step 5: Create Controller by Command
  • Step 6: Create Blade View
  • Step 7: Run Development Server

Step 1: Install wkhtmltopdf Software

In thi step we will first install wkhtmltopdf software. Follow the instruction given below to install:

For Ubuntu:

for Windows:

You have go the following link and download exe. Then install it:

Step 2: Download Laravel Fresh App

First of all we need to create a fresh laravel project, download and install Laravel using the below command

Step 3: Install mikehaertl/phpwkhtmltopdf

In this step, we will install mikehaertl/phpwkhtmltopdf Package via the composer dependency manager. Use the following command to install mikehaertl/phpwkhtmltopdf Package.

Step 4: Add Routes

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

 

Step 5: Create Controller by Command

Now, lets create a controller named GraphPdfController using command given below –

This command will create a controller that name GraphPdfController.php.

Next go to app/Http/Controllers and open GraphPdfController.php. Then update the following methods into your controller file:

Step 6: Create View File

Go to resources/views/ folder and create a new blade view file that name graph.blade.php file.

After that, update the following code into your graph.blade.php file:

Step 7: Run Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

In this tutorial we have learn about the Laravel 7 Generate PDF with Graph and its application with practical example. I hope you will like this tutorial.