Laravel:从带有图像的刀片导出PDF

时间:2018-06-27 10:17:08

标签: php laravel image pdf tcpdf

我正在尝试使用TCPDF将带有图像的桌面刀片导出到PDF。

我的控制器:

public function exportPDF(){
      $users = User::orderBy('id','DESC')->get();
     $view = View::make('admin.users.export',compact('users'));
     $contents = (string) $view;
      $contents = $view->render();
     $pdf = new PDF();
  $pdf::SetTitle('Users List');
  $pdf::SetSubject('Users List');
  $pdf::SetKeywords('User');
  $pdf::SetTitle('User List');
  $pdf::AddPage();
  $pdf::writeHTML($contents, true, false, true, false, '');
  $pdf::Output('users.pdf');
}

我的刀片:

<html>
<head>
<body>
<h4>Users List</h4>
<table>
<tr>
<th>Image</th>
<th>First Name</th>
<th>Last Name</th>
<th>User Name</th>
<th>Email</th>
<th>Role</th>
</tr>     
@if($users->count())  
@foreach($users as $user)  
<tr> 
<td><img src="{{asset('images/users/'.$user->image_path)}}"></td> 
<td>{{$user->first_name}}</td>
<td>{{$user->last_name}}</td>
<td>{{$user->username}}</td>
<td>{{$user->email}}</td>
<td>{{$user->role}}</td>
</tr>
@endforeach 
</table>
</body>
</html>

但是当我想获取pdf时,它需要很长时间,之后它给了我此消息

  

TCPDF错误:[图像]无法获得图像的大小:http://127.0.0.1:8000/images/users/1523518590.jpg

谢谢

0 个答案:

没有答案