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
Celebian logo

Celebian

Celebian is a social media marketing agency specializing in helping their clients go viral on TikTok. Whether you're looking to reach a bigger audience or gain more Tiktok followers, likes, and views, they've got you covered.

Celebian
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
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
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud