Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mvnobrega's avatar

Cannot resolve public path domPDF [ SOLVED ]

I installed DOMpdf and includes it as well as config/app.php :

'providers' => [
	....
	Barryvdh\DomPDF\ServiceProvider::class,
],
  
'aliases' => [
	....
	'PDF' => Barryvdh\DomPDF\Facade::class,
]

It looks all right, but when I go to use it, I'm getting the following error (Cannot resolve public path), see :

 $this->app->bind('dompdf', function ($app) {

 

            $options = $app->make('dompdf.options');

            $dompdf = new Dompdf($options);

            $path = realpath(base_path('public'));

            if ($path === false) {

                throw new \RuntimeException('Cannot resolve public path');

            }

            $dompdf->setBasePath($path);

 

            return $dompdf;

        });

What could be happening?

0 likes
9 replies
Snapey's avatar
Snapey
Best Answer
Level 122

do you have 'public' folder ?

1 like
mvnobrega's avatar

@Snapey

I don't know which folder the error refers to. But my site is inside public_html, as you would expect

mvnobrega's avatar

@Snapey the error occurs when I call my view in the controller. But it's strange, I don't understand the reason for the error

$pdf = PDF::loadView('pdf')

mvnobrega's avatar

@Snapey

I managed to solve. I just created the public folder and it solved... hehe

Thanks

3 likes
Snapey's avatar

@mvnobrega No I WOULD NOT EXPECT YOUR PROJECT TO BE IN PUBLIC_HTML

Thats just stupid and insecure

mvnobrega's avatar

@Snapey Inside it has only the files from the public folder of laravel. All the rest of the files are outside of public_html

thedevshezzy's avatar

This issue is submitted to DOMPDF Git already and people have found workaround of it.

Go to this path

vendor/barryvdh/laravel-dompdf/src

Edit

ServiceProvider.php

Search for

base_path('public')

and replace it with

public_path()

OR YOU CAN JUST CREATE A PUBLIC FOLDER IN YOUR CODEBASE DIRECTORY

EDIT: This happens when your code base has no public folder and you have separated your public folder to public_html.

4 likes
dkvadratu's avatar

Package domPDF has own config file in Laravel project /config/dompdf.php

Set custom public_path param. Like:

'public_path' => base_path('public_html')

alwinfau's avatar

Hi everybody i have an error when i want to display report in pdf format. the error is "Cannot resolve public path". Can anyone help me, where do you think the error is coming from?

Please or to participate in this conversation.