laravel-php-pdf maintained by dskripchenko
dskripchenko/laravel-php-pdf
Laravel bridge for
dskripchenko/php-pdf— the pure-PHP, MIT-licensed PDF toolkit (generate, read, merge). No GPL friction, faster than mpdf/dompdf, and conformance-validated on every push.
Installation
composer require dskripchenko/laravel-php-pdf
The service provider and the Pdf facade register automatically
(package discovery). Optionally publish the config:
php artisan vendor:publish --tag=php-pdf-config
Usage
HTML → PDF
use Dskripchenko\LaravelPhpPdf\Facades\Pdf;
// bytes
$bytes = Pdf::fromHtml('<h1>Invoice #1234</h1>')->bytes();
// file
Pdf::fromHtml(view('invoices.show', $data)->render())->save(storage_path('invoice.pdf'));
// HTTP responses
Route::get('/invoice', fn () => Pdf::fromHtml($html)->inline('invoice.pdf'));
Route::get('/invoice/download', fn () => Pdf::fromHtml($html)->download('invoice.pdf'));
response()->pdf()
The macro accepts a PendingPdf, a php-pdf Document (either layer), or
raw bytes — the mpdf Output('', 'D') habit, the Laravel way:
return response()->pdf(Pdf::fromHtml($html), 'invoice.pdf'); // inline
return response()->pdf(Pdf::fromHtml($html), 'invoice.pdf', inline: false); // download
Programmatic documents
$document = Pdf::builder()
->heading(1, 'Quarterly report')
->paragraph('Q1 revenue exceeded the forecast by 12%.')
->build();
return Pdf::render($document)->download('report.pdf');
Everything from the underlying toolkit is reachable — charts, barcodes, AcroForm fields, PDF/A, encryption, PKCS#7 signing, and reading/merging existing PDFs. See the php-pdf documentation.
Configuration
config/php-pdf.php controls page defaults and fonts:
'paper' => 'a4', // a3..a6, letter, legal, tabloid, executive
'orientation' => 'portrait',
'margins' => ['top' => null, 'right' => null, 'bottom' => null, 'left' => null], // pt
'fonts' => [
// Embedded TTFs (required for Cyrillic, Greek, Arabic, CJK — the
// base-14 defaults cover Latin only). Fonts are subset automatically.
'default' => storage_path('fonts/DejaVuSans.ttf'),
'bold' => storage_path('fonts/DejaVuSans-Bold.ttf'),
// Named families for CSS font-family / RunStyle(fontFamily: ...):
'families' => [
'mono' => ['regular' => storage_path('fonts/DejaVuSansMono.ttf')],
],
],
'metadata' => ['Author' => 'ACME Corp.'], // default /Info entries
Migrating from laravel-mpdf / barryvdh wrappers
The underlying toolkit ships compat facades and guides for mpdf and FPDI call sites.
Requirements
- PHP 8.2+
- Laravel 11, 12, or 13
- Extensions:
mbstring,zlib,dom(plusopensslfor encryption/signing)
Testing
composer test
License
MIT. The underlying dskripchenko/php-pdf is MIT as well — no GPL
obligations anywhere in the stack.