Try Depot: Bring ultra-fast, remote Docker builds directly to your Laravel workflow

Laravel Dompdf

barryvdh/laravel-dompdf image

Laravel Dompdf stats

Downloads
37.9M
Stars
6,124
Open Issues
72
Forks
925

View on GitHub →

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

  1. Laravel:

    composer require barryvdh/laravel-dompdf
  2. 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-before and page-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.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Barryvdh Laravel Dompdf Related Articles

Laravel Debugbar Gets a Big UI Update image

Laravel Debugbar Gets a Big UI Update

Read article
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $3200/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell