Laravel dompdf error "Image not found or type unknown"

Laravel dompdf error "Image not found or type unknown"

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Deciphering the "Image Not Found or Type Unknown" Error in DomPDF

Encountering the Image not found or type unknown error when generating PDFs with DomPDF is a common frustration, particularly when dealing with dynamic image paths stored in storage links like public/storage/images/.... The root cause isn't necessarily that the file doesn't exist on your filesystem; it's how DomPDF interprets relative paths within HTML strings versus how Laravel resolves them for browser rendering.

When you pass a view to PDF::loadView(), DomPDF renders that HTML into a PDF document. In a standard browser, an <img> tag with src="public/storage/images/..." triggers Laravel's public asset pipeline, resolving the path relative to the web server root. However, DomPDF operates in a sandboxed environment where it treats the content string literally. It does not automatically invoke Laravel's URL generation logic or resolve public storage symlinks unless explicitly told to do so.

If you replace the dynamic variable with a static filename like image_1.jpg, the error vanishes because the path is treated as a direct relative reference from the document root, which DomPDF can successfully access if the file exists there. The moment you inject a database value into the src attribute, DomPDF attempts to resolve that string as an absolute URL or a path relative to the current working directory of the PHP process, rather than the web root. Since the generated HTML likely contains something like <img src="/storage/images/john_doe.jpg"> (depending on how the view is rendered) or simply src="storage/images/...", DomPDF fails to locate the resource in its expected location.

To fix this, you must ensure DomPDF receives an absolute path or a fully qualified URL that it can resolve. The most robust approach involves manipulating the image source before passing the view to the PDF generator. You have two primary strategies: providing a full filesystem path or converting the storage link into a public URL that DomPDF respects.

Using Absolute Filesystem Paths

The most direct solution is to modify your Blade template to accept an absolute path instead of a relative storage link. You can achieve this by prefixing the path with public_path() and ensuring the extension is preserved.

Update your view file logic to handle the image source explicitly:

<img src="{{ public_path('storage/images/' . $user->profile_pic) }}" alt="" style="width: 150px; height: 150px;" />

By using public_path(), you force DomPDF to look for the file in the physical directory structure of your application. This bypasses the ambiguity of relative paths and ensures the "type unknown" error doesn't occur due to missing headers or incorrect path resolution. Note that if your storage link is mounted at /storage in your web.php route file, you might also pass the URL directly:

<img src="{{ url('storage/images/' . $user->profile_pic) }}" alt="" style="width: 150px; height: 150px;" />

Using url() generates a full HTTP URL (e.g., http://localhost/storage/...). DomPDF handles absolute URLs well, but it is crucial that the image data is actually accessible via HTTP if you choose this route, or that DomPDF is configured to fetch remote resources.

Configuration and Limitations

DomPDF has specific limitations regarding image handling. By default, it may not follow redirects or handle certain MIME types correctly if the server headers are missing. If you continue to face issues even after switching to absolute paths, check your config/dompdf/dompdf.php file. Ensure that the isRemoteEnabled setting is appropriate for your use case, though for local storage images, relying on absolute filesystem paths is generally safer and more performant.

Additionally, verify that the image extension in your database matches the actual file on disk exactly. DomPDF is strict about MIME types; a .jpeg file referenced as .jpg might trigger type errors depending on how strict the loader is configured. Consistency between the stored path and the filesystem is key.

For complex PDF generation requirements, consider exploring alternative packages like barryvdh/laravel-dompdf, which offers enhanced configuration options for handling media types and paths. While DomPDF is lightweight, its strictness regarding image resolution often necessitates these explicit path adjustments to ensure high-quality, error-free PDF exports.

Our network