Oh Dear is the all-in-one monitoring tool for your entire website. We monitor uptime, SSL certificates, broken links, scheduled tasks and more. You'll get a notifications for us when something's wrong. All that paired with a developer friendly API and kick-ass documentation. O, and you'll also be able to create a public status page under a minute. Start monitoring using our free trial now.

Generate pdfs with Google Chrome on a Forge provisioned server

Original – by Freek Van der Herten – 1 minute read

While working on one of our projects my colleague Sebastian had to create a pdf with some text and charts. In a new post on his blog he explains how he leveraged headless Chrome to create the pdf.

This week I needed to export some charts generated with HTML & JavaScript as a pdf file. I already had implemented the charts on a webpage so I wanted a solution that allowed me to use my existing code for the pdfs.

Headless Chrome to the rescue! Chrome can run as a cli tool, and print a pdf file from a url. Al I had to do was make some layout tweaks to make everything printer-friendly.

https://sebastiandedeyne.com/posts/2017/generate-pdfs-with-google-chrome-on-a-forge-provisioned-server

Meanwhile support for creating pdfs has been added to our Browsershot package (which also uses headless Chrome under the hood).

Here's how you can convert a webpage to a pdf using the package:

Browsershot::url('https://example.com')->save('example.pdf');

Stay up to date with all things Laravel, PHP, and JavaScript.

You can follow me on these platforms:

On all these platforms, regularly share programming tips, and what I myself have learned in ongoing projects.

Every month I send out a newsletter containing lots of interesting stuff for the modern PHP developer.

Expect quick tips & tricks, interesting tutorials, opinions and packages. Because I work with Laravel every day there is an emphasis on that framework.

Rest assured that I will only use your email address to send you the newsletter and will not use it for any other purposes.

Comments

What are your thoughts on "Generate pdfs with Google Chrome on a Forge provisioned server"?

Comments powered by Laravel Comments
Want to join the conversation? Log in or create an account to post a comment.