Laravel Dompdf
Laravel Dompdf stats
- Downloads
- 37.9M
- Stars
- 6,124
- Open Issues
- 72
- Forks
- 925
A DOMPDF Wrapper for Laravel
Summary of Laravel DOMPDF Wrapper
The Laravel DOMPDF Wrapper, created by Barryvdh, is a package that facilitates the conversion of HTML to PDF within Laravel applications. It leverages the capabilities of the Dompdf HTML to PDF converter, providing a seamless integration with the Laravel framework.
Key Features
- Easy Integration: Quick setup with Laravel and Lumen that involves adding the service provider and optionally publishing the configuration file.
- Flexible HTML Rendering: Allows rendering from HTML strings, files, or Blade views directly into PDF.
- Configurable: Offers options to customize paper size, orientation, and even font settings through the published configuration.
- Chaining Methods: Fluent interface to chain method calls like loading HTML, setting options, and outputting the PDF.
- Output Options: Supports various output methods including saving to a file, streaming (to open in a browser), and downloading directly.
Installation Instructions
-
Laravel:
composer require barryvdh/laravel-dompdf -
Lumen: After updating composer, register the provider in
bootstrap/app.php:$app->register(\Barryvdh\DomPDF\ServiceProvider::class);
Usage Examples
-
Generating and downloading a PDF from a view:
use Barryvdh\DomPDF\Facade\Pdf;$pdf = Pdf::loadView('pdf.invoice', $data);return $pdf->download('invoice.pdf'); -
Streaming a PDF from HTML content:
$pdf = App::make('dompdf.wrapper');$pdf->loadHTML('<h1>Test</h1>');return $pdf->stream(); -
Custom Configuration: Publish and edit the configuration file using:
php artisan vendor:publish --provider="Barryvdh\DomPDF\ServiceProvider"Customize settings like DPI, default font, and paper size as needed.
Tips for Effective Usage
- UTF-8 Support: Ensure your HTML templates include the UTF-8 meta tag for proper character rendering.
- Page Breaks: Manage page breaks in PDFs using CSS properties
page-break-beforeandpage-break-after.
Conclusion
The Laravel DOMPDF Wrapper is an essential package for developers looking to generate PDFs from HTML in Laravel applications, providing robust customization options and easy usage.
License
This package is open-sourced under the MIT license.