Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

feniixx's avatar

PNG to PDF Laravel 5.0

I would like to know how could i grab a screenshot of a route, and stream it as a pdf. I would like to do this because DOMPdf doesn't support things like Bootstrap, neither Snappy, i would like to export to pdf a complete view...

The best solution i've thinked is to take a screenshot with Screenly, but how could i stream that to PDF in the browser?

Also if there's a simpler way to do that it would be amazing!

0 likes
4 replies
willvincent's avatar

I dunno if it's simpler, but you could leverage node to generate screenshots for you, and then generate a pdf from the resulting screenshot image with php... See: https://github.com/brenden/node-webshot

The major problems with generating a pdf from an image are that a) it won't be text-searchable, and b) the filesize will be considerably larger.

Are these routes only ever going to be used for generating a pdf (a report, for example) or do people need to access them in their browsers too? If they're only going to be used for pdf generation, you could drastically simplify matters by limiting their styling to only things that do work with dompdf, or another pdf library.

feniixx's avatar

@willvincent hmmm, by now i've done my reports with dompdf, but i would like something more stylish... and dompdf doesnt let me use bootstrap or other style frameworks...

do you know about a better way of make rich reports in laravel or php?

willvincent's avatar

If you're able to install wkhtmltopdf on your server, you could use this php wrapper library: https://github.com/mikehaertl/phpwkhtmltopdf

That uses the webkit renderer, so should work just fine with bootstrap or anything else. Also being a compiled server-side application, it's considerably faster than any php implementation of pdf generation. Just be aware that it uses the print styles, so you may need to tweak those as I'm fairly certain the default print styles for bootstrap strip out colors and such.

If you can't install wkhtmltopdf, and/or just want to play with it a bit first, you could use this: http://www.spurdoc.com/

Please or to participate in this conversation.