wkhtmltopdf with laravel homestead using xvfb-run

Lately i’ve been experimenting with generating a pdf from a html/css page and stumbled upon wkhtmltopdf. It’s a nice library full of options and I was impressed with the results.

I wanted to use the library in my laravel homestead environment and was running into some problems. Specifically:

QXcbConnection: Could not connect to display

After some digging I found: xvfb-run

xvfb-run is a simplified wrapper for xvfb which is a virtual framebuffer that can run right on your server. Since you don’t have a display or might not even have a video card running on your server, you’ll be able to “emulate” your screen viewing the page wkhtmltopdf is trying to generate a pdf from.

I was able to install both these libraries super easy:
sudo apt-get xvfb-run
sudo apt-get wkhtmltopdf

Then I was able to successfully get wkhtmltopdf running on my laravel homestead server running a command like this:

xvfb-run --auto-servernum --server-num=0 wkhtmltopdf --print-media-type --page-size letter http://yourwebsitehere.com yourdocument.pdf

Hope this helped save someone some time !

WordPress ShareThis Plugin Shortcode

I’ve used the sharethis wordpress plugin for quite some time now. As a web designer and someone who is constantly working on new themes it’s been a pain not to have a shortcode to display the buttons.
Thanks to wordpress we can use the functions.php file of your default theme to create are own shortcode to do the trick!

Continue reading » WordPress ShareThis Plugin Shortcode