Home > Blockchain >  Cant Load Image Using Dompdf Laravel 9
Cant Load Image Using Dompdf Laravel 9

Time:01-19

the image when i run without domPDF will come out, but if i use domPDF its say like this enter image description here

this is my html code

<img src="{{public_path('assets/img/logoprov.png')}}" height="100" width="100">
<img src="{{public_path('img/logoprov.png')}}" height="100" width="100">
<img src="{{asset('img/logoprov.png')}}" height="100" width="100">

this is my controller code

$surat = Surat::find($id);
view()->share('surat',$surat);
$pdf = PDF::loadView('sekretariat.pdf.index',compact('surat'));
return $pdf->download('pdf_file.pdf');

CodePudding user response:

1st you need to set the tempDir and chroot from you controller.

$pdf = PDF::loadView('sekretariat.pdf.index',$surat)->setOptions([
            'tempDir' => public_path(),
            'chroot' => public_path()
        ]);

And in your dompdf view page load the image as:

<img src="{{ public_path('assets/img/logoprov.png') }}" alt="Logo">
  • Related