barryvdh / laravel-dompdf

A DOMPDF Wrapper for Laravel
MIT License
6.66k stars 966 forks source link

Image not found or type unknown #1059

Open GanonthaBr opened 2 months ago

GanonthaBr commented 2 months ago

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

ZARk-be commented 2 months ago

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') }}' />

parallels999 commented 2 months ago

@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