barryvdh / laravel-dompdf

A DOMPDF Wrapper for Laravel
MIT License
6.77k stars 976 forks source link

Public image not showing Laravel 10 #1058

Open matiassemelman opened 4 months ago

matiassemelman commented 4 months ago

Hello there, I'm using Laravel 10.10, and package 2.1.

I have my logo on public/ folder, just there. This is my function: private function generateLogo() { return "<img src='{{public_path('./pathful-logo') }}' alt='pathful-logo' class='logo' />"; }

I used public_path(), base_path(), with and without {{ }}.

GanonthaBr commented 4 months ago

I am facing the same issue but with Laravel 11.x.x

parallels999 commented 4 months ago

did you try with asset()?

Also https://github.com/barryvdh/laravel-dompdf/issues/1059#issuecomment-2218671789

chanakaDe commented 3 months ago

I'm facing the same issue in Laravel 11.x :-(

sven-ahrens commented 3 months ago

Can confirm.

Tried it with helper methods like asset, tried absolute and relative paths, also tried SetOptions (Which, even if it would be expected behaviour, would be weird)

I just get this screen.

Bildschirmfoto 2024-08-05 um 11 25 24

Nasty Hack

What actually works and it's a workaround for me: Just encode your file in base64 ;)

'logo' => 'data:image/png;base64,' . base64_encode(file_get_contents(public_path('images/logo.png'))),
sven-ahrens commented 3 months ago

Hm actually, got to apologize: Made it work with public_path.

@matiassemelman did you try it without the leading ./ in your scenario?

In my example:

src="{{ public_path('/images/logo.png') }}"

it does work

but in your scenario the output would be something like: "/application/public/./images/logo.png"

the dot actually ruins the path

GanonthaBr commented 3 months ago

Laravel 11.x

I was able to fix the problem with:

$imagePath = public_path('images/logo.png'); $image = "data:image/png;base64," . base64_encode(file_get_contents($imagePath));

inside my controller and passed the $image vairiable down to the view which allowed me to used it inside my <img> tag easily like this: <img src="{{$image}}"/>

Check my Controller here: https://github.com/GANONTHA/Belle-House-Automated-Invoice/blob/master/app/Http/Controllers/PDFExportController.php

Sahrija commented 3 months ago

Laravel 11.x

I was able to fix the problem with:

$imagePath = public_path('images/logo.png'); $image = "data:image/png;base64," . base64_encode(file_get_contents($imagePath));

inside my controller and passed the $image vairiable down to the view which allowed me to used it inside my <img> tag easily like this: <img src="{{$image}}"/>

Check my Controller here: https://github.com/GANONTHA/Belle-House-Automated-Invoice/blob/master/app/Http/Controllers/PDFExportController.php

bro, you saved my live, i was figuring this problem for days