Here’s a collection of steps needed to create PDF files directly from HTML web pages.
Table of Contents
ToggleHow to Convert Web (HTML) Pages into PDF Files
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/wkhtmltopdf.sh exit sudo chmod a+x /usr/bin/wkhtmltopdf.sh sudo ln -s /usr/bin/wkhtmltopdf.sh /usr/local/bin/wkhtmltopdf
How to Convert Web (HTML) Pages into PDF Files
Once the installation is complete, simply run the following command to make sure that everything went well:
wkhtmltopdf http://www.google.com output.pdf
This will generate a PDF file called output.pdf
which will contain a preview of the Google’s homepage.
1 Comment
Comments are closed.
For Symfony2 users I recommend using the https://github.com/KnpLabs/KnpSnappyBundle bundle for wkhtmltopdf “out of the box” functionality.