NO FUNCIONA BÉ AMB BOOSTRAP! Vegeu Snappy
$ composer require dompdf/dompdf
http://pxd.me/dompdf/www/examples.php#print_header_footer.html,pdf
Vista: https://github.com/laravel/cashier/blob/6.0/resources/views/receipt.blade.php
/** * PDF a view with parameters * * @param array $data * @return string */ public function pdf(array $data) { if (! defined('DOMPDF_ENABLE_AUTOLOAD')) { define('DOMPDF_ENABLE_AUTOLOAD', false); } if (file_exists($configPath = base_path().'/vendor/dompdf/dompdf/dompdf_config.inc.php')) { require_once $configPath; } $dompdf = new DOMPDF; $dompdf->load_html($this->view($data)->render()); $dompdf->render(); return $dompdf->output(); } /** * Create an invoice download response. * * @param array $data * @return \Symfony\Component\HttpFoundation\Response */ public function download(array $data) { $filename = $data['product'].'_'.$this->date()->month.'_'.$this->date()->year.'.pdf'; return new Response($this->pdf($data), 200, [ 'Content-Description' => 'File Transfer', 'Content-Disposition' => 'attachment; filename="'.$filename.'"', 'Content-Transfer-Encoding' => 'binary', 'Content-Type' => 'application/pdf', ]); } /** * Get the View instance for the invoice. * * @param array $data * @return \Illuminate\View\View */ public function view(array $data) { return View::make('cashier::receipt', array_merge( $data, ['invoice' => $this, 'user' => $this->user] )); }
Instal·leu:
composer require dompdf/dompdf
From within a route or controller, use the downloadInvoice method to generate a PDF download of the invoice. This method will automatically generate the proper HTTP response to send the download to the browser:
Route::get('user/invoice/{invoice}', function ($invoiceId) { return Auth::user()->downloadInvoice($invoiceId, [ 'vendor' => 'Your Company', 'product' => 'Your Product', ]); });
No funciona bé amb Bootstrap! https://github.com/dompdf/dompdf/issues/631