Currently, there are two major packages allowing the PDF generation in Laravel applications: Laravel-DomPDF by barryvdh and Laravel-PDF by Spatie. I will compare these two packages by seeing what they offer. Both packages allow users to utilize Blade templates in Laravel, which can be converted to PDF.
barryvdh/laravel-dompdf
laravel-dompdf is a wrapper for the package dompdf/dompdf, responsible for converting HTML files to PDFs. barryvdh/laravel-dompdf is dedicated to Laravel applications. At the time of writing this post, it is still being developed to support new versions of Laravel. Reading through the description of dompdf/dompdf, we learn that its rendering engine was written in PHP. At the moment, it supports most attributes from HTML4 and most values from CSS2.1, as well as selected ones from CSS3. This is a disadvantage because many modern HTML and CSS features will not be supported. The repository states that CSS features such as flexbox or grid are currently not supported.
spatie/laravel-pdf
spatie/laravel-pdf is a new package dedicated to Laravel. It was released around the turn of the year 2023/2024. It is not a wrapper but a package that utilizes a ready-made rendering engine. In the documentation, you can find information that Chromium is used as the rendering engine, so it can be expected to support HTML5 and CSS3 functionalities.
In the documentation of laravel-pdf, you can also find information that we can utilize the Tailwind framework for our PDFs. Tailwind can be used either via CDN or added to the project through Vite.
Here, you will also find additional functionality for developers, such as support for testing generated PDFs. spatie/laravel-pdf offers the ability to generate fake PDFs. In tests, we can check things like whether the file was created in the correct location, whether it was returned correctly, whether it was created based on the correct Blade template, or if it contains the specified text fragment.