laravel-dompdf icon indicating copy to clipboard operation
laravel-dompdf copied to clipboard

Public image not showing Laravel 10

Open matiassemelman opened this issue 1 year ago • 7 comments

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 {{ }}.

matiassemelman avatar Jun 28 '24 13:06 matiassemelman

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

GanonthaBr avatar Jul 05 '24 14:07 GanonthaBr

did you try with asset()?

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

parallels999 avatar Jul 09 '24 22:07 parallels999

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

chanakaDe avatar Jul 29 '24 11:07 chanakaDe

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 avatar Aug 05 '24 09:08 sven-ahrens

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

sven-ahrens avatar Aug 05 '24 09:08 sven-ahrens

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

GanonthaBr avatar Aug 06 '24 12:08 GanonthaBr

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

sahrija avatar Aug 20 '24 20:08 sahrija