Laravel Dompdf花了太长时间下载pdf

时间:2018-05-31 12:30:30

标签: laravel laravel-5 laravel-5.5 dompdf

我想在Laravel 5.5中使用Dompdf从刀片模板制作pdf发票。

问题是当点击下载按钮时页面正在加载,大约3分钟后,pdf开始下载。

为什么需要这么长时间?

下载链接

<a href="{{ route('admin.download-invoice', $order->OrderID) }}" target="_blank" class="btn btn-danger"><i class="fa fa-file-pdf-o"></i> Download Invoice</a>

网络路线:

Route::get('/order/download-invoice/{OrderID}', 'Admin\AdminOrderController@downloadOrderInvoice')->name('admin.download-invoice');

一个简单的模板(invoice.blade.php)

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other 
head content must come *after* these tags -->
<title>Invoice</title>
<link rel="stylesheet" href="{{ asset('css/bootstrap.min.css') }}" media="screen">
</head>
<body>
   <div>{{ $invoice->InvoiceTitle }} </div>
</body>
</html>

下载发票控制器功能:

use Barryvdh\DomPDF\Facade as PDF;
public function downloadOrderInvoice($OrderID){  

    $invoice = Invoice::where('OrderID', $OrderID)->first();
    $pdf = PDF::loadView('invoice.invoice', compact('invoice'))->setPaper('a4', 'landscape');

    return $pdf->download('invoice.pdf');
}

我做错了什么?我错过了什么吗?

更新

清除标题并使用EXTERNAL CDN bootstrap工作。

<head>
<meta charset="utf-8">    
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>

为什么不使用资产本地引导程序???

<link href="{{asset('css/bootstrap.min.css')}}" rel="stylesheet">

1 个答案:

答案 0 :(得分:-3)

<?php ini_set('max_execution_time', 0); ?>