Brainstorming ways to solve this problem
Kinda unrelated to filament, but I am going to use this feature in a filament panel so I might as well just ask here:
I am looking for a way to generate PDFs based on (1) data from my model and (2) a pre-made design. kinda like how udemy and other course sites generate custom certificates.
Here is an idea I just came up with: somehow make a bunch of templates in html & css with some parts of it being customizable then allow the user to customize the template (e.g. change the logo, color palette, etc..) and finally export it to pdf.
but I have no idea how that would work in practice.
if anyone has any better ideas/ something similar implemented in laravel or filament / a totally different idea let me know!
10 Replies
Most reliable way is to use a headless chrome browser to render and export to PDF. Look at spatie/browsershot package
If your html/css is not too "fancy" (css3 flexbox etc) you can use Laravel Snappy https://github.com/barryvdh/laravel-snappy which uses wkhtmltopdf bin, and is WAYYYYYY faster than using headless chrome, and way more accurate than using DomPDF. The part of generating the layouts based on data, is straight forward Laravel+Blade.
GitHub
GitHub - barryvdh/laravel-snappy: Laravel Snappy PDF
Laravel Snappy PDF. Contribute to barryvdh/laravel-snappy development by creating an account on GitHub.
Just be aware that
wkhtmltopdf
is abandoned. It probably still works, but it might break in the future.
wkhtmltopdf
uses the Webkit engine from 2012wkhtmltopdf
works flawlessly, it's available on major Linux repos, through composer, and other sources. It's a very nice midpoint between DomPDF and full out headless Chrome. The risk of breaking in the future totally worth it! πhmm, I really need to think this through. it seems like I will end up with some technical debt with whatever option I go with
If you want it "future proof", i say go with Browsershot and Puppeteer. But give Laravel Snappy a shot, if it renders your html/css the way it should, the ease of use and performance pays off.
I think that's the way to go
thank you for the suggestions
You can exchange "technical debt" against paying for a service like https://www.api2pdf.com/pricing/.
api2pdf
Api2Pdf
Pricing - Api2Pdf
Get started for free Create an account and receive one month of free credit to try out the service. Have more pricing questions? See our FAQ.
what about just generating the html and instructing the user to "print to PDF" through their own browser, are there any downsides to that?
I mean that's what I do personally when I want to update my CV, I have a
resume/
page on my site, I edit it in my code editor and ctrl+P to print to pdf.No downside apart from user experience. Depends on your application.