sglms / pdf
Simple Laravel wrapper for mPDF with fluent view rendering and signing helpers.
0.4
2026-04-29 19:11 UTC
Requires
- php: >=8.3
- illuminate/support: ^12.0
- illuminate/view: ^12.0
- mpdf/mpdf: ^8.2
Requires (Dev)
- laravel/framework: ^12.0
This package is auto-updated.
Last update: 2026-04-29 20:19:24 UTC
README
Simple Laravel wrapper around mPDF with a fluent API for rendering Blade views, attaching headers/footers, and signing documents.
Requirements
- PHP >= 8.3
- Laravel 12
- mPDF 8.2+
Installation
composer require sglms/pdf
Laravel package discovery registers the service provider and facade automatically.
Quick Start
use Sglms\Pdf\Facades\Pdf; Pdf::view('pdf.invoice', ['order' => $order])->output('invoice.pdf');
Usage
Initialize with configuration
use Sglms\Pdf\Facades\Pdf; $pdf = Pdf::init( config: ['format' => 'Letter'], stylesheet: 'css/pdf.css', header: 'pdf.header', footer: 'pdf.footer' );
Render one or multiple views
$pdf->view('pdf.page-one', ['name' => 'Jane']) ->view('pdf.page-two') ->output('document.pdf');
Add logo for header/footer views
The logo is available in mPDF templates as var:logo.
$pdf->logo('images/logo.svg');
If your header or footer uses the logo, call logo() before header() / footer().
Add signature block
$pdf->sign( signature: 'pdf.signature', data: ['name' => 'John Doe'], x: 50, y: 100, width: 100 );
Sign existing PDF
$pdf->signFile('pdf.signature', storage_path('app/base.pdf'));
Output options
// Raw string — pass to Laravel's response() helper $raw = $pdf->output('document.pdf'); $raw = $pdf->string(); // alias, no filename context // Write to an absolute file path $pdf->save(storage_path('app/a.pdf')); // Laravel Storage disk $pdf->storeAs('a.pdf', 'public'); // Stream directly to the browser (bypasses Laravel response) $pdf->inline('document.pdf'); // Content-Disposition: inline $pdf->download('document.pdf'); // Content-Disposition: attachment
Access underlying mPDF instance
$mpdf = $pdf->get();
Controller Example
use App\Http\Controllers\Controller; use Sglms\Pdf\Facades\Pdf; class CustomController extends Controller { public function render() { $bytes = Pdf::view('pdf.filename') ->sign('pdf.signature') ->output('document.pdf'); return response($bytes, 200) ->header('Content-Type', 'application/pdf') ->header('Content-Disposition', 'inline; filename="document.pdf"'); } }
Notes
- mPDF applies headers/footers from the point they are set. Set header/footer before the first rendered body view when possible.
- This package is intentionally lightweight and optimized for straightforward document-generation workflows.
License
MIT