Developer654079525's avatar

PDF library

We want to export parts of our website into a downloadable, self-contained PDF file with the TOC. It will be generated from a separate, hidden layer of our app that has custom CSS. So, it would be nice, if the rendered PDF somewhat closely matches the CSS HTML look. Which library that plays nicely with Laravel 12.* would you recommend (for a commercial use)?

0 likes
3 replies
jlrdw's avatar

Look at barryvdh/laravel-dompdf also Spatie has a PDF library.

DigitalArtisan's avatar

HTML with CSS to PDF never works well. Good luck if you rely on JS views.

The best for me has been as mentioned above the barryvdh/laravel-dompdf. I use Blade views, ~/resources/views/print/pdf/.... Minimal CSS, overridden from the HTML pages, pretend your in the 90s writing HTML email. You cannot do fancy things, as the DOMPDF library does not support all CSS.

I've been doing HTML to PDF for just over 15 years.

Other options are using libreoffice headless. Best is to design your PDF documents, then dynamically fill them.

Best way to test is using your web browsers Print Preview -> Print to PDF. From what I remember, Firefox was the best.

1 like
Snapey's avatar

I outsource pdf creation to third parties. Via api, You send them the html referencing your external stylesheets, they render the pdf and return it.

I have had good results with Neutrino API https://www.neutrinoapi.com/api/html-render/ but other similar services are available.

1 like

Please or to participate in this conversation.