mohammad nabipour
mohammad nabipour

Reputation: 119

How to use image in pdf

I used laravel-pdf (https://github.com/niklasravnsborg/laravel-pdf) package. I want to use img tag in my PDF view.

My controller code:

public function generatePdf()
{
    $pdf= Pdf::loadView('resume::resumePdf', compact('resume'));
    return $pdf->stream('document.pdf');
}

My view:

<!doctype html>
<html lang="fa" dir="rtl">
<head>
    <head>
        <meta charset="UTF-8">

        <style>
            body {
                font-family: persianfont;
            }
        </style>
    </head>
</head>

<body>

</body>
   <img id="resumeProfileImage" src="url('/images/avatar.png')" width="100" height="100"/>
</html>

When I run this code, no show error, just is loading.

Upvotes: 1

Views: 1937

Answers (2)

VIKAS KATARIYA
VIKAS KATARIYA

Reputation: 6005

Use

<img src="'. public_path() .'/images/avatar.png">

Upvotes: 2

Muhammad Dyas Yaskur
Muhammad Dyas Yaskur

Reputation: 8138

You should encode the image to base64 first. First, you need to get raw image first using file_get_contents('/images/avatar.png') or Storage::get('/images/avatar.png') or something other, then you encode it to base64 using base64_encode() function

Example code

<img src="data:image/png;base64, {!! base64_encode(file_get_contents('/images/avatar.png')) !!}" width="100" height="100">

Upvotes: 0

Related Questions