Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

DomPDF shows a broken image in a Laravel PDF

Errordompdf: image not found or type unknown

Short 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.

  • Applies to barryvdh/laravel-dompdf 3.x, dompdf 3.x, Laravel 12
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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/
  2. 2Match what you see, then jump to its fix

    1. 1src starts with http:// or https://The image is a remote URL and remote access is offFix
    2. 2src is a local path to a file in another directory, for example a mounted diskThe local file is outside the chrootFix
    3. 3src is like images/logo.png or ../images/logo.pngA relative path resolves to the wrong placeFix

What does the error look like?

  • dompdf: image not found or type unknown
  • Image 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.php

2Fix

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:clear

Confirmed by github.com

Did this fix it?

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.php

2Fix

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:clear

Confirmed by github.com

Did this fix it?

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:clear

Confirmed by github.com

Did this fix it?

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 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 fix

Back 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.