Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

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 v4.0.0 is released image

Laravel Debugbar v4.0.0 is released

Read article
Laravel Debugbar Gets a Big UI Update image

Laravel Debugbar Gets a Big UI Update

Read article
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
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
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
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