Here’s a collection of steps needed to create PDF files directly from HTML web pages.

If you’re working on a Ubuntu Linux machine, the first thing you need to do is to install the WKHTMLTOPDF library, by running the following commands into your terminal:

sudo apt-get install wkhtmltopdf
sudo apt-get install xvfb
sudo su
echo 'xvfb-run --server-args="-screen 0, 1024x768x24" /usr/bin/wkhtmltopdf $*' > /usr/bin/
sudo chmod a+x /usr/bin/
sudo ln -s /usr/bin/ /usr/local/bin/wkhtmltopdf

Once the installation is complete, simply run the following command to make sure that everything went well:

wkhtmltopdf output.pdf

This will generate a PDF file called output.pdf which will contain a preview of the Google’s homepage.