Laravel Image to PDF File

In this article, we will show you laravel image to PDF file. This article will give you simple example of laravel image to PDF file. you will learn laravel image to PDF file.

You need to just follow bellow step to create pdf file and also can download. So let’s do bellow steps.

This article will give you simple example of laravel image to PDF file of how to add laravel image to PDF file Function in laravel 6, laravel 7 and laravel 8 version.

Step 1:- Install Laravel

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

Step 2:- Install dompdf Package

composer require barryvdh/laravel-dompdf


'providers' => [




'aliases' => [


	'PDF' => Barryvdh\DomPDF\Facade::class,


Step 3:- Add Route



Step 4:- Add Controller



namespace App\Http\Controllers;


use Illuminate\Http\Request;

use PDF;


class PDFController extends Controller



     * Display a listing of the resource.


     * @return \Illuminate\Http\Response


    public function generatePDF()


        $data = ['title' => 'Welcome to'];

        $pdf = PDF::loadView('myPDF', $data);


        return $pdf->download('codeplaners.pdf');



Step 5:- Create View File

Here, you have to add two images on following path:



In Last step, let’s create myPDF.blade.php(resources/views/myPDF.blade.php) for layout of pdf file and put following code:


<!DOCTYPE html>



    <title>Laravel Image to PDF File - codeplaners</title>



    <h1>Welcome to - {{ $title }}</h1>

    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod

    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,

    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo

    consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse

    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non

    proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>



    <strong>Public Folder:</strong>

    <img src="{{ public_path('dummy.jpg') }}" style="width: 200px; height: 200px">


    <strong>Storage Folder:</strong>

    <img src="{{ storage_path('app/public/dummy.jpg') }}" style="width: 200px; height: 200px">



Now we are ready to run this example and check it…

Recommended Posts