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

dpakagarwal's avatar

Error while generating pdf using dompdf in laravel 8

i have created an invoice and its working fine but when i export as pdf it throws me an error as below:

Undefined variable $title (View: C:\xampp\htdocs\bls\resources\views\mypdf.blade.php)

and sometimes as

Symfony\Component\HttpFoundation\Response::setContent(): Argument #1 ($content) must be of type ?string, Barryvdh\DomPDF\PDF given, called in C:\xampp\htdocs\bls\vendor\laravel\framework\src\Illuminate\Http\Response.php on line 72

as i am using barryvdh dompdf package for exporting. please help me if anyone knows it this is controller methid as below:

$fetchData = Invoice::findOrFail($id);
        $data = [
            'title' => 'Invoice',
        ];
        // $pdf =  PDF::loadHTML($viewHtml); // generated fast
        $pdf =  PDF::loadView('mypdf', $data); // takes max execution time to load pdf
        return $pdf->download('invoice.pdf');

and this is my mypdf.blade.php file:

<div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
        <div class="breadcrumb-title pe-3">{{ $title }}</div>
    </div>
0 likes
6 replies
tisuchi's avatar

@deepakagarwal Shouldn't it be $data['title']?


<div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
        <div class="breadcrumb-title pe-3">{{ $data['title'] }}</div>
</div>
dpakagarwal's avatar

@tisuchi i have done what you have said but throws another error:

Undefined variable $data (View: C:\xampp\htdocs\bls\resources\views\admin\Invoice\mypdf.blade.php)

Please or to participate in this conversation.