pdf-laravel5
DOMPDF module for Laravel 5. Export your views as PDFs - with css support.
Instalation
Add:
"vsmoraes/laravel-pdf": "^2.0"
To your composer.json
or Run:
composer require vsmoraes/laravel-pdf
Then add:
VsmoraesPdfPdfServiceProvider::class
To the providers
array on your config/app.php
And
'PDF' => 'VsmoraesPdfPdfFacade',
To the aliases
array on yout config/app.php
in order to enable the PDF facade
Usage
Route::get('/pdf/view', function() { $html = view('pdfs.example')->render(); return PDF::load($html)->show(); });
Force download
Route::get('/pdf/download', function() { $html = view('pdfs.example')->render(); return PDF::load($html)->download(); });
Return PDF as string
Route::get('/pdf/output', function() { $html = view('pdfs.example')->render(); return PDF::load($html) ->output(); });
Set paper size and orientation
Route::get('/pdf/output', function() { $html = view('pdfs.example')->render(); return PDF::load($html, 'A4', 'landscape') ->output(); });
Output to a file
Route::get('/pdf/output', function() { $html = view('pdfs.example')->render(); PDF::load($html) ->filename('/tmp/example1.pdf') ->output(); return 'PDF saved'; });
Inject on your controller
<?php namespace AppHttpControllers; use VsmoraesPdfPdf; class HomeController extends BaseControler { private $pdf; public function __construct(Pdf $pdf) { $this->pdf = $pdf; } public function helloWorld() { $html = view('pdfs.example1')->render(); return $this->pdf ->load($html) ->show(); } }
Configuration
Dompdf allows you to configure a bunch of things on your PDF file. In previous versions we used to accomplish this through environment vars, now you can change this configuration keys on the fly:
Route::get('/pdf/view', function() { $html = view('pdfs.example')->render(); $defaultOptions = PDF::getOptions(); $defaultOptions->setDefaultFont('Courier'); return PDF::setOptions($defaultOptions)->load($html)->download(); });
For the complete configuration reference: Dompdf options
版权声明:
1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。2、网站不提供资料下载,如需下载请到原作者页面进行下载。
3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考学习用!
4、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。