2016-04-12 41 views
1

我已經使用DoomPDF包在Laravel中完成了PDF輸出。但是,表格的第一行似乎錯了位置,僅在第一個紙上。有誰知道爲什麼?Laravel/w Bootstrap PDF

控制器:

public function printPDF(PDF $pdf) 
{ 
    $users = User::all(); 
    $pdf->loadView('pdf.index', compact('users')); 
    return $pdf->setOrientation('landscape')->setPaper('A4')->stream(); 
} 

版式文件:

<!doctype html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <title>Document</title> 

    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"> 

</head> 
<body> 

<table class="table table-striped"> 
    <tbody> 
    @foreach($users as $user) 
     <tr> 
      <td><strong>{{$user->name}}</strong></td> 
      <td>{{$user->address}} <br> {{$user->city}}</td> 
      <td>{{$user->phone_private}} <br> {{$user->phone_work}}</td> 
      <td>{{$user->email}} <br> {{$user->email_private}}</td> 
      <td>{{$user->oib}}</td> 
     </tr> 
    @endforeach 
    </tbody> 
</table> 
</body> 
</html> 

結果: Image

+0

因此,'pdf.index'視圖僅包含'

'及其內容並且沒有其他標記? – Bogdan

+0

不,它是完整的html。 Head有引導依賴加載,就是這樣。更新 – Norgul

+0

如果您嘗試在瀏覽器中顯示視圖,而不是在PDF中,會發生什麼情況? – Hammerbot

回答

1

似乎有an issue with Dompdf這Laravel DOMPDF內部使用生成的PDF文件。它可以很容易地固定加入這個CSS規則視圖文件:

<style> 
    thead:before, thead:after, 
    tbody:before, tbody:after, 
    tfoot:before, tfoot:after 
    { 
     display: none; 
    } 
</style> 

有一個fix committed for this bug大約一個星期前,但它是dompdf/dompdf V0.7和the stable v0.6.1 release of barryvdh/laravel-dompdf使用較早dompdf/dompdf V0.6。因此,如果您想要使用穩定版本,則可以使用上述CSS修復程序,直到barryvdh/laravel-dompdf v0.7已完成。