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

Image not found or type unknown

Open GanonthaBr opened this issue 1 year ago • 3 comments

I am using Laravel 11. On my generated pdf, the image is not being loaded.

GanonthaBr avatar Jul 08 '24 11:07 GanonthaBr

If you are using images from local drive, you need to tell DomPDF to allow that filepath.

ex: if your images are in your storage/app/compressed folder : Pdf::SetOptions(['chroot' => [Storage::drive('public')->path('compressed')] ])->loadView(.....)

And in your view, you have to put the full file path again

<img src='{{ Storage::drive('public')->path('compressed/myImage1.jpg') }}' />

ZARk-be avatar Jul 09 '24 20:07 ZARk-be

@ZARk-be hi, be carefull, setOptions remove all the configs better use setOption or add bool $mergeWithDefaults argument

// with setOption
Pdf::setOption('chroot', [Storage::drive('public')->path('compressed')])->loadView(.....)
// or setting bool $mergeWithDefaults arg on setOptions
Pdf::setOptions(['chroot' => [Storage::drive('public')->path('compressed')]], true)->loadView(.....)

https://github.com/barryvdh/laravel-dompdf/blob/d7ccbc3af7f52fec496bc4aebd099f917b1d2a57/src/PDF.php#L152-L156 https://github.com/barryvdh/laravel-dompdf/blob/d7ccbc3af7f52fec496bc4aebd099f917b1d2a57/src/PDF.php#L163-L171

parallels999 avatar Jul 09 '24 22:07 parallels999

Embedd images like this <img src="{{ public_path('resources/img/logo-big.jpg') }}" id="brand" alt="Logo" >

apmedev avatar Oct 04 '24 05:10 apmedev