GitHub - vsmoraes/pdf-laravel5: DOMPDF module for Laravel 5 https://github.
com/vsmoraes/pdf-laravel5
vsmoraes / pdf-laravel5
Dismiss
Join GitHub today
GitHub is home to over 31 million developers working together to host
and review code, manage projects, and build software together.
Sign up
DOMPDF module for Laravel 5
# pdf # dompdf # php # pdf-laravel5 # laravel # laravel-5-package # html # css
39 commits 1 branch 5 releases 4 contributors View license
Branch: master New pull request Find File Clone or download
vsmoraes Merge pull request #27 from rankovic/master … Latest commit 84805f1 on 21 Aug 2017
src Fix service provider 2 years ago
tests Initialize version 2.0 2 years ago
.gitignore Adding support for travis-ci 4 years ago
.travis.yml Bump php versions on travis 2 years ago
LICENSE Adding support for travis-ci 4 years ago
README.md add example for changing paper size and orientation to readme 2 years ago
composer.json Initialize version 2.0 2 years ago
phpunit.xml Initialize version 2.0 2 years ago
README.md
pdf-laravel5
DOMPDF module for Laravel 5. Export your views as PDFs - with css support.
build passing stable 2.0 downloads 92.02 k unstable dev-master license MIT
Instalation
Add:
"vsmoraes/laravel-pdf": "^2.0"
To your composer.json
or Run:
composer require vsmoraes/laravel-pdf
Then add:
1 de 3 4/15/19, 3:02 p. m.
GitHub - vsmoraes/pdf-laravel5: DOMPDF module for Laravel 5 https://github.com/vsmoraes/pdf-laravel5
Vsmoraes\Pdf\PdfServiceProvider::class
To the providers array on your config/app.php
And
'PDF' => 'Vsmoraes\Pdf\PdfFacade',
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
2 de 3 4/15/19, 3:02 p. m.
GitHub - vsmoraes/pdf-laravel5: DOMPDF module for Laravel 5 https://github.com/vsmoraes/pdf-laravel5
<?php namespace App\Http\Controllers;
use Vsmoraes\Pdf\Pdf;
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
3 de 3 4/15/19, 3:02 p. m.