Generate PDF with charts and data without a browser

Hi,

I have an app based on Yii2 basic and as part of it, I have pages where I can generate reports (charts using chart.js and data in Yii2 grid) and I have export to PDF button which works fine and includes the charts and the grid or table.

What I want to achieve is to somehow make it “web callable” and be able to produce the PDF (with the charts) and return it as a file. In other words try to achieve this without using a browser.

I have done some research and gone through several posts and was wondering whether going the headless browser path is the right option for this or not. I know PhantomJS is archived and no longer in development but both Chrome and Firefox have their headless versions now. The main reason I’m wondering if I may need a headless browser is because of the charts and not just the data which may be easier to convert to PDF. Also, with my app both the charts and the PDF generation are done using javascript, so I don’t know if I can reuse any of my code in case I want to perform this on the server side (if that’s a possibility).

I found a package called browsershot (https://github.com/spatie/browsershot) which seem to be doing what I’m after (using headless Chrome) and it does have a wrapper for Laravel (https://github.com/verumconsilium/laravel-browsershot) but don’t know if anything similar exists for Yii2. The other option I’m thinking of trying is the wkhtmltopdf command line tool (it does seem to have PHP libraries too) but I don’t know if the charts will work with that.

Any advice or heads up is appreciated.

Thank you.