我在我的項目中使用DOMPDF,並且在我的系統中實現了一些測試之前,我已經運行了服務,它告訴我超過60秒的時間, 創建控制器:Laravel 5 barryvdh/laravel-dompdf time exceeded
public function invoice()
{
$data = $this->getData();
$date = date('Y-m-d');
$invoice = "2222";
$view = \View::make('pdf.invoice', compact('data', 'date', 'invoice'))->render();
$pdf = \App::make('dompdf.wrapper');
$pdf->loadHTML($view);
return $pdf->stream('invoice');
}
public function getData()
{
$data = [
'quantity' => '1' ,
'description' => 'some ramdom text',
'price' => '500',
'total' => '500'
];
return $data;
}
然後我添加路由:
Route::get('pdf', '[email protected]');
最後一部分我補充的是在視圖中的文件夾名稱的PDF和文件invoice.blade.php:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Example 2</title>
<link rel="stylesheet" href="{{asset('plugins/bootstrap/css/bootstrap.css')}}">
</head>
<body>
<main>
<div id="details" class="clearfix">
<div id="invoice">
<h1>INVOICE {{ $invoice }}</h1>
<div class="date">Date of Invoice: {{ $date }}</div>
</div>
</div>
<table border="0" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th class="no">#</th>
<th class="desc">DESCRIPTION</th>
<th class="unit">UNIT PRICE</th>
<th class="total">TOTAL</th>
</tr>
</thead>
<tbody>
<tr>
<td class="no">{{ $data['quantity'] }}</td>
<td class="desc">{{ $data['description'] }}</td>
<td class="unit">{{ $data['price'] }}</td>
<td class="total">{{ $data['total'] }} </td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="2"></td>
<td >TOTAL</td>
<td>$6,500.00</td>
</tr>
</tfoot>
</table>
</body>
<script src="{{asset('plugins/jquery/js/jquery-2.1.4.js')}}"></script>
<script src="{{asset('plugins/bootstrap/js/bootstrap.js')}}" ></script>
</html>
URL:http://localhost:8000/pdf
我真的很感激,如果有人能告訴我我的錯誤在哪裏。
你確定你正確設置laravel-dompdf嗎?爲什麼不使用'PDF :: loadView('pdf.invoice',$ data)''就像文檔中建議的那樣? – phaberest