Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image not found or type unknown #1059

Open
GanonthaBr opened this issue Jul 8, 2024 · 3 comments
Open

Image not found or type unknown #1059

GanonthaBr opened this issue Jul 8, 2024 · 3 comments

Comments

@GanonthaBr
Copy link

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

@ZARk-be
Copy link

ZARk-be commented Jul 9, 2024

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
Copy link

parallels999 commented Jul 9, 2024

@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(.....)

laravel-dompdf/src/PDF.php

Lines 152 to 156 in d7ccbc3

public function setOption($attribute, $value = null): self
{
$this->dompdf->getOptions()->set($attribute, $value);
return $this;
}

laravel-dompdf/src/PDF.php

Lines 163 to 171 in d7ccbc3

public function setOptions(array $options, bool $mergeWithDefaults = false): self
{
if ($mergeWithDefaults) {
$options = array_merge(app()->make('dompdf.options'), $options);
}
$this->dompdf->setOptions(new Options($options));
return $this;
}

@apmedev
Copy link

apmedev commented Oct 4, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants