Here's the one I have used, it is a Laravel wrapper for the DomPDF one you linked:
https://github.com/barryvdh/laravel-dompdf
Have used it to convert views into PDFs easily.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
An app I'm developing has a need to be able to print forms with exact precision. Does anyone have experience actually using Snappy or DomPDF for generating pdf's from a laravel application?
Which one would you recommend?
Traditionally I used fpdf in the past, but it is cumbersome and hardly easy to maintain. The reason I need to generate pdf's is so they will print consistently. Just hoping to get some advice from anyone who has actually used these libraries. Cheers!
Here's the one I have used, it is a Laravel wrapper for the DomPDF one you linked:
https://github.com/barryvdh/laravel-dompdf
Have used it to convert views into PDFs easily.
Thanks @noeldiaz ! I should've mentioned that I saw barryvdh's wrappers for both libraries. Did you find that dompdf was pretty precise when comparing the pdf version to your original view?
Not sure what you mean by "precise", but positioning through CSS "position: absolute" seems to be working well. Also, using an image and then position text on top works.
@witkai -- precise as in how accurately it renders the given view in pdf form. The reason I ask is I'll be dealing with automated testing (scantron) forms and they will need to be exact to be scored by the machine properly. Thanks for your input! I was mostly just wondering what people's experiences were with either of the two. I assume you're also using dompdf? This is what I'm leaning towards using as well.
I'm using Snappy PDF with the Laravel wrapper, and it's pretty neat. It has its limitations, but it's superior to the other alternatives I've used because it allows you to use a Bootstrap grid, which was a requirement for the project I've used it in :-)
For my uses it has been very precise. But I have been also making some simpler looking views to display the data that will be put into the PDF. Basically like a "print-view" like version that I can confidently make into a PDF without all the boilerplate of my normal site. In that case it has worked great.
Thanks for your great replies everyone! I'll start with one of the libraries (probably dompdf) and can always swap if I find it isn't quite precise enough. Anything is better than fpdf. I'll be sure to make an update post if I run into any issues or simply to list my experiences within a few weeks. Happy holidays all!
Have you heard of mPDF? It has been around for a few years and although the code base is horrific it's pretty powerful.
https://packagist.org/packages/lowerends/l4-mpdf https://packagist.org/packages/mpdf/mpdf http://www.mpdf1.com
mPDF is absolute garbage. If you are looking for precision then do not even waste your time looking into it. The problem with mPDF is it's completely PHP based which is just natively incapable of generating PDFs, while snappy is a wrapper around wkhtmltopdf which is a binary which needs to be installed on your system. mPDF supports almost no modern CSS or HTML elements and working with it is as much of a nightmare as it's code is.
I use Snappy on our project after using mPDF on a few others in the past. I must say that I've never seen something work so perfectly. When I first installed it I ran some tests and tried to generate a PDF of various websites around the internet (you can just give it a URL to "PDFerize"). Among the sites I tested were espn.com and cnn.com and both PDFs came out picture-perfect, representing the real websites exactly. His wrapper also makes it very easy to implement it inside of Laravel -- you can just pass it a view name to render, or an HTML string, or a URL, etc. It also supports forms.
My recommendation is for snappy ;)
Like I said, the code base is horrific. I'm sure it's a nightmare to maintain and to add new features but it's still has its uses. If you just want to compile some simple html for a report then it's not too bad but I agree that for anything complicated I would go with something else.
I don't mean to attack your recommendation, please don't take it personal -- just from my experience I would never suggest mPDF to any other developer. My time with it was a complete nightmare. It doesn't support floats, borders, absolute positioning, etc.. They even have a page (http://mpdf1.com/manual/index.php?tid=34) that documents their (lack of) CSS support. The fact that they need to document what's supported is an automatic turn off when compared to the others options. Snappy (or wkhtmltopdf rather) basically has no limitations -- it takes almost a perfect picture of what you're trying to render.
Even with the simplest of markup I had troubles with mPDF's horrid implementation. The only time it would have a use in my opinion is if you didn't have the ability to install the wkhtmltopdf binary on your server and mpdf is then your only choice.
I've used wkhtmltopdf, although not recently.
A different approach where it's a binary that needs to exist on your host you pipe the url through and runs your page via a webkit web browser and pdfs the result.
As the creator of those 2 wrappers, I must say: Snappy (wkhtmltopdf) is the best.
DomPDF is fine for many cases (table-based views, invoices etc) but anything you want to do with complex html/css, just use snappy. The only reason I would use DomPDF is because not every shared hosting is easy to setup wkhtmltopdf. If you have your own server, just install wkhtmltopdf for your system and you are all set for fast PDFs :)
Edit: You can use both packages actually. The Facade API is pretty much the same for basic stuff, so you can just swap those two packages if you need to :)
Just used
https://github.com/barryvdh/laravel-dompdf
and it works amazingly especially when using it with a view file. I use this so the user can either send the PDF direct to a customer or make a printable page so they can send it via mail.
mPDF is still by far the best solution that I've found. It only took 5 minutes of looking at dompdf to see it wasn't even a contender. Just a couple of features of mPDF that destroy dompdf right from the start: automated TOC generation with hotlinks and bookmark generation, a pagebreak tag for forcing a pagebreak in markup (with the option to reconfigure all the aspects of the new page), and automatic page numbering. If you just need to spit out a copy of a web page, I guess dompdf works fine, but if you actually need to generate a document, mPDF is the way to go, especially if you need exact precision. It has a bit of a learning curve, but it's not that steep. The only issue real issue I've had with it is being unable to float within a float. I've used it to make lots of things from legal documents to maps to status reports.
I haven't used it with Laravel yet (I'm about to, which is how I ended up here) but I don't anticipate it being a problem at all.
I trying to create pdf files too but im a bit confused what should i install. First, i suspect i need to install this: http://wkhtmltopdf.org/downloads.html But after that, should i install https://github.com/KnpLabs/snappy and https://github.com/barryvdh/laravel-snappy both or what? Can someone please show me what exactly i need to install?
You should install binary from http://wkhtmltopdf.org/downloads.html, then use https://github.com/barryvdh/laravel-snappy for wrapper inside your Laravel app
Thank you @ghprod
I've used the same dompdf laravel-snappy thing that a lot of others mentioned. It took some time to get it all working. Turned out I was using an older version of wkhtmltopdf. That could be something to watch out for.
I found it quite precise. Since you're working with print stuff, you can use mm sizing in your css and with absolute positioning, you can put things anywhere you want. (hey, you're the one deciding the size of the medium also. No responsive/resolution stuff here :P )
Please or to participate in this conversation.