tjgazel / laravel-fpdf
Extension lib FPDF for laravel 5.*
Installs: 1 673
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:package
Requires
- php: >=5.4.0
This package is auto-updated.
Last update: 2024-11-20 20:07:20 UTC
README
install
1) Composer
composer require tjgazel/laravel-fpdf
2) Optional: Laravel 5.4 and below
Add TJGazel\Toastr\ToastrServiceProvider::class
to providers
in config/app.php
.
Add 'Toastr' => TJGazel\Toastr\Facades\Toastr::class
to aliases
in config/app.php
.
// config/app.php
'providers' => [
// ...
TJGazel\LaraFpdf\LaraFpdfServiceProvider::class,
],
'aliases' => [
// ...
'LaraFpdf' => TGazel\LaraFpdf\Facades\LaraFpdf::class,
],
Usage
(Method 1) Facade
use App\Http\Controllers\Controller; use TGazel\LaraFpdf\Facades\LaraFpdf; class MyController extends Controller { public function index() { LaraFpdf::AddPage(); LaraFpdf::SetFont('Courier', 'B', 18); LaraFpdf::Cell(50, 25, 'Hello World!'); LaraFpdf::Output('I', "MyPdf.pdf", true); exit; } }
(Method 2) Extends class
create your pdf class
namespace App\Pdf; use TJGazel\LaraFpdf\LaraFpdf; class MyPdf extends LaraFpdf { private $data public function __construct($data) { $this->data = $data; parent::__construct('P', 'mm', 'A4'); $this->SetA4(); $this->SetTitle('My pdf title', true); $this->SetAuthor('TJGazel', true); $this->AddPage('L'); $this->Body(); } public function Header() { // fixed all pages } public function Body() { $this->SetFont('Arial', 'B', '24'); $this->Cell(50, 25, $this->data->title); $this->SetFont('Arial', '', '14'); $this->Cell(50, 25, $this->data->content); } public function Footer() { // fixed all pages } }
In your controll
use App\Http\Controllers\Controller; use App\Pdf\MyPdf; class MyController extends Controller { public function index() { $data = MyModel::all(); $myPdf = new MyPdf($data); $myPdf->Output('I', "MyPdf.pdf", true); exit; } }