curiousteam / laravel-pdf-drivers
Driver-based PDF generator for Laravel (mPDF, Dompdf, Html2Pdf) with a unified API.
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/curiousteam/laravel-pdf-drivers
Requires
- php: ^8.2
- illuminate/contracts: ^11.0||^12.0
- illuminate/support: ^11.0||^12.0
- mpdf/mpdf: ^8.2
Requires (Dev)
- orchestra/testbench: ^10.0.0||^9.0.0
README
A simple, driver-based PDF generation manager for Laravel.
Supports multiple PDF libraries (drivers) such as mPDF, Dompdf, TCPDF, and more.
Installation
You can install the package via composer:
composer require curiousteam/laravel-pdf-drivers
You can publish the config file with:
php artisan vendor:publish --provider="Curiousteam\LaravelPdfDrivers\PdfServiceProvider" --tag="config"
If you are on Laravel < 5.5, you need to manually register the service provider:
// config/app.php 'providers' => [ Curiousteam\LaravelPdfDrivers\PdfServiceProvider::class, ],
Configuration
After publishing, you’ll get a config file at config/pdf.php:
return [ 'driver' => env('PDF_DRIVER', 'mpdf'), // dompdf|mpdf|html2pdf 'drivers' => [ 'dompdf' => [ 'options' => [ 'isHtml5ParserEnabled' => true, 'isRemoteEnabled' => true, 'defaultFont' => 'DejaVu Sans', ], 'paper' => ['size' => 'A4', 'orientation' => 'portrait'], ], 'mpdf' => [ 'options' => [ 'mode' => 'utf-8', 'format' => 'A4', 'tempDir' => storage_path('app/mpdf-temp'), 'default_font' => 'dejavusans', ], 'paper' => ['size' => 'A4', 'orientation' => 'landscape'], ], 'html2pdf' => [ 'options' => [ 'format' => 'A4', 'orientation' => 'P', 'language' => 'en', 'unicode' => true, 'encoding' => 'UTF-8', 'margins' => [10, 10, 10, 10], ], 'paper' => ['size' => 'A4', 'orientation' => 'portrait'], ], ], ];
Usage
Basic Example
use Curiousteam\LaravelPdfDrivers\Facades\Pdf; Route::get('/download-report', function () { $html = view('templates.pdf.reports.example', ['title' => 'Laravel PDF Driver'])->render(); return Pdf::loadHTML($html) ->download('report.pdf'); });
Streaming PDF in Browser
return Pdf::loadView('templates.pdf.reports.invoice', ['invoice' => $invoice]) ->stream('invoice.pdf');
Saving PDF to Disk
Pdf::loadHTML('<h1>Hello CuriousTeam</h1>') ->save(storage_path('app/reports/hello.pdf'));
Switching Drivers
Default installed driver is: mpdf
To use other driver (Dompdf\Dompdf or Spipu\Html2Pdf), you need to install the package via composer first:
composer require dompdf/dompdf
Or,
composer require spipu/html2pdf
Then, you can easily switch drivers at runtime:
$pdf = Pdf::driver('dompdf') ->loadView('reports.test') ->download('test.pdf');
Or, even dynamically in .env:
PDF_DRIVER=dompdf
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.