Laravel Add Image to PDF File Example

In this post, we will learn laravel pdf images not showing. you can understand a concept of laravel pdf add image example. you will learn laravel pdf insert image. This post will give you simple example of laravel add image to pdf example. follow bellow step for laravel generate pdf with image.

PDF is one of basic requirement when you are working with erp level project or e commerce website. we may need to create pdf file or maybe you also need to add image with pdf file, might be logo or product image etc. So, here i will give you very simple example for create pdf file with laravel.

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

.Step 1: Install Laravel 7

I am going to explain step by step from scratch so, we need to get fresh Laravel 7 application using bellow command, So open your terminal OR command prompt and run bellow command:

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

Step 2: Install dompdf Package

first of all we will install barryvdh/laravel-dompdf composer package by following composer command in your laravel 7 application.

composer require barryvdh/laravel-dompdf

After successfully install package, open config/app.php file and add service provider and alias.


'providers' => [

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

Step 3: Add Route

In this is step we need to create routes for items listing. so open your “routes/web.php” file and add following route.



Step 4: Add Controller

Here,we require to create new controller PDFController that will manage generatePDF method of route. So let’s put bellow code.



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('laratuto.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>
    <h1>Welcome to - {{ $title }}</h1>
    <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…

I hope it can help you…