PHP code example of vsmoraes / laravel-pdf
1. Go to this page and download the library: Download vsmoraes/laravel-pdf library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vsmoraes / laravel-pdf example snippets
Vsmoraes\Pdf\PdfServiceProvider::class
'PDF' => 'Vsmoraes\Pdf\PdfFacade',
Route::get('/pdf/view', function() {
$html = view('pdfs.example')->render();
return PDF::load($html)->show();
});
Route::get('/pdf/download', function() {
$html = view('pdfs.example')->render();
return PDF::load($html)->download();
});
Route::get('/pdf/output', function() {
$html = view('pdfs.example')->render();
return PDF::load($html)
->output();
});
Route::get('/pdf/output', function() {
$html = view('pdfs.example')->render();
return PDF::load($html, 'A4', 'landscape')
->output();
});
Route::get('/pdf/output', function() {
$html = view('pdfs.example')->render();
PDF::load($html)
->filename('/tmp/example1.pdf')
->output();
return 'PDF saved';
});
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();
}
}
Route::get('/pdf/view', function() {
$html = view('pdfs.example')->render();
$defaultOptions = PDF::getOptions();
$defaultOptions->setDefaultFont('Courier');
return PDF::setOptions($defaultOptions)->load($html)->download();
});