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

harryg's avatar

Generating PDF reports with charts

I want to build a reporting service that can produce a pdf report consisting of a basic template and also feature charts.

The idea I have is to use a blade view template and render it into a pdf using something like Laravel Snappy. I am aware of charting libraries such as chart.js which are nice-looking and easy to use. However, they rely on javascript to render the charts which does not play nice with server-side pdf renderers. I reckon the best approach is if the chart be rendered as an svg which can be styled accordingly. There is the chartist library which produces stylable svg output but it too is client-side.

Can anyone suggest a nice server-side solution to producing a pdf report from an html template containing charts, or at least a reliable way to render javascript-generated charts?

UPDATE

It seems laravel-snappy (i.e. wkhtmltopdf) is able to process client-side javascript in an html template. It remains to be seen how more complex templates come out but a basic chartist.js example is working.

I'd still be keen to hear how others have gone about this as I imagine this is a semi-common task.

0 likes
1 reply
Felix's avatar

I'm using phantomjs to convert a blade view into a PDF.

Did you use chart.js? I have the problem right now, that the HTML5 Canvas has blurry text and in the PDF rendered version its even worse.

Someone have another suggestion for a good chart library that works well with PDF rendering?

Please or to participate in this conversation.