Dkna
Dkna

Reputation: 437

dompdf image not showing in blade file laravel

I keep getting this error, Maximum execution time of 60 seconds exceeded, whenever I try to download my pdf and I have look around and most of the people said to change php.ini max_execution time. I have already done that but still getting the error. I change it at the folder xampp/php.ini, not sure if it is the correct one. I tried looking under my laravel project for php.ini but there is no such file there. Another thing that I tried was putting ini_set('max_execution_time', 60); at the top of my blade.php but still doesn't work. Can anyone help me? Thanks in advance

test.blade.php

<?php ini_set('max_execution_time', 60); ?>
<div class="container">
@foreach($object as $test)
@if( $pdf == 0 )
  <a href="{{url('/pdfview')}}{{$test->id}}">Download PDF</a>
  @endif
@endforeach
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
    border: 2px solid black;
    width: 60%;
}
</style>
</head>
<body>
<table align="center">
  <tr>
    <th>Designation</th>
    <th>
      @foreach($data3 as $currentUser)
      <img src="{{ url('images/' . $currentUser->name ) }}">
      @endforeach
    </th>
  </tr>
 </table>
</body>
</html>
</div>

pdfDownloadController.php (will get undefined error when downloading pdf so did this)

   public function pdfview($id)
    {

        $object = personal_info::where('id',$id)->get();
        $object1 = additional_info::where('user_id',$id)->get(); 
         $data3=UserImage::where('user_id',$id)->get();
         $object4 = language::where('user_id',$id)->get();

        $pdf = PDF::loadView('test', compact('id','object','object1','data3','object4'), array('pdf' => true));
        return $pdf->download('test.pdf');
          return view('test', array('pdf' => false));
    }

testController: //show in test.blade.php

     public function getBiodata($id){

          $object = personal_info::where('id',$id)->get();

        $object1 = additional_info::where('user_id',$id)->get(); 
         $data3=UserImage::where('user_id',$id)->get();
         $object4 = language::where('user_id',$id)->get();
          $pdf = PDF::loadView('biodata', compact('id','object','object1','data3','object4'), array('pdf' => 1));

     return view('biodata',compact('id','object','object1','data3','object4'),array('pdf' => 0 ));

 }

Upvotes: 3

Views: 7119

Answers (3)

muoki_D
muoki_D

Reputation: 409

2024, if anyone is having a similar problem and looking for a solution, ensure your image is base64 encoded and provide the absolute path using either base_path() or storage_path() depending on where your image is. For the case above, it would look something like this:

<img src="data:image/png;base64,<?php echo base64_encode(file_get_contents(base_path('public/images/'.$currentUser->name))); ?>" />

I hope this helps someone.

Upvotes: 0

Md. Hasanat Zamil
Md. Hasanat Zamil

Reputation: 11

The following code is working fine:

name ) }}"> or name ) }}">

Upvotes: 1

kunal
kunal

Reputation: 4248

As i have done i one of my project :- Changed this:-

<img src="{{ url('images/' . $currentUser->name ) }}">

To:-

<img src="./images/{{$currentUser->name}} />

Hope it helps!

Upvotes: 4

Related Questions