DomPDF shows a broken image in a Laravel PDF
dompdf: image not found or type unknownShort answer
DomPDF loads images itself, not through the browser. Remote URLs are blocked until isRemoteEnabled is on, local files must sit under the chroot directory, and relative paths resolve against a base path. Use an absolute local path, or enable remote access for the images you trust.
Fix it fast
1Find out which cause you have
Look at the src of the failing image in the Blade view. Whether it is a URL, an absolute path or a relative path decides which cause applies.
grep -rn "<img" resources/views/pdf/2Match what you see, then jump to its fix
- 1
src starts with http:// or https://The image is a remote URL and remote access is offFix - 2
src is a local path to a file in another directory, for example a mounted diskThe local file is outside the chrootFix - 3
src is like images/logo.png or ../images/logo.pngA relative path resolves to the wrong placeFix
- 1
What does the error look like?
dompdf: image not found or type unknownImage shows as a broken box in the generated PDF
Cause 1 of 3
The image is a remote URL and remote access is off
1Check
Since version 3 remote access is disabled by default for security. DomPDF will only load images and CSS over web protocols when isRemoteEnabled is true.
grep -n "remote" config/dompdf.php2Fix
Publish the config and turn the remote option on, or better, switch the image to a local file. The README warns to use remote access with caution. allowedRemoteHosts can restrict which hosts are allowed.
php artisan vendor:publish --provider="Barryvdh\DomPDF\ServiceProvider"3Verify
Generate the PDF again and open it.
php artisan optimize:clearConfirmed by github.com
Cause 2 of 3
The local file is outside the chroot
1Check
dompdf reads local files only from the directories set in chroot. The laravel-dompdf default is the application directory.
grep -n "chroot" config/dompdf.php2Fix
Keep the image under the application directory, or add its folder to chroot. Do not set chroot to / because the dompdf docs warn against it.
<img src="{{ public_path('images/logo.png') }}" alt="Logo">3Verify
Generate the PDF; the image appears.
php artisan optimize:clearConfirmed by github.com
Cause 3 of 3
A relative path resolves to the wrong place
1Check
Relative paths resolve against the base path, or against the location of the loaded file. An absolute path ignores the base path.
grep -rn "src=\"[^h/{]" resources/views/pdf/2Fix
Use an absolute filesystem path built with public_path() instead of a relative one.
<img src="{{ public_path('images/logo.png') }}" alt="Logo">3Verify
Generate the PDF again and open it.
php artisan optimize:clearConfirmed by github.com
How do I stop it coming back?
- Put PDF images in a folder inside the project and reference them with absolute paths.
- Leave remote access off unless a template really needs it, and restrict hosts when on.
- Keep one test route that renders each PDF template during development.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Composer says the gd extension is missing on a Laravel project
composer install or composer update stops on a package that requires ext-gd
Composer refuses to install a package that requires ext-gd when the PHP binary running Composer has no GD extension.
4 causes, each with a fixBack end
composer require maatwebsite/excel fails to install
Composer says the package needs an older PHP than the one installed
Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.
3 causes, each with a fixBack end
composer install says the lock file is not compatible and asks for update
Your lock file does not contain a compatible set of packages. Please run composer update.
composer install checked the locked packages against this machine's PHP and extensions and found a conflict.
3 causes, each with a fixBack end
composer require laravel/horizon fails: ext-pcntl is missing
laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system
Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.
3 causes, each with a fixBack end
composer require laravel/passport stops with 'requirements could not be resolved'
... but these were not loaded, likely because it conflicts with another require.
Composer found no Passport release that fits your project at once.
4 causes, each with a fixBack end
Composer says the root composer.json requires a PHP version your PHP does not satisfy
Your requirements could not be resolved to an installable set of packages.
Composer compares the php constraint in your composer.json, or in a package, with the PHP that runs Composer.
3 causes, each with a fix