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
Securing Laravel logo

Securing Laravel

The essential security resource for Laravel devs, covering everything you need to keep your apps secure. Sign up to receive weekly security tips and monthly in depth articles, diving deep into security concepts you need to know!

Securing Laravel
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
Tighten logo

Tighten

We help companies turn great ideas into amazing apps, products, and services.

Tighten
MongoDB logo

MongoDB

Enhance your PHP applications with the powerful integration of MongoDB and Laravel, empowering developers to build applications with ease and efficiency. Support transactional, search, analytics and mobile use cases while using the familiar Eloquent APIs. Discover how MongoDB's flexible, modern database can transform your Laravel applications.

MongoDB
Tinkerwell logo

Tinkerwell

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

Tinkerwell
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