HTML to PDF conversion is now possible from within the browser. You can convert any HTML webpage into a PDF file using browser add-ons/extensions. But that’s too mainstream! I’d rather like to convert any webpage into PDF using the Linux command line. That’s more like it!
For this purpose, you’ll need to simple utilities: wget, which will be used for downloading the webpage and wkhtmltopdf, which will be used for converting the downloaded webpage (HTML file) into PDF. wget is installed by default in most Linux distros. But you may have to download and install wkhtmltopdf using your distros’ package manager. Don’t worry! Just execute the following commands as told, and you’ll be prompted if either one is not installed.
- Use the command below to download the webpage that you want to turn into PDF:
wget -p link_of_the_webpage
Copy the link of the webpage from the browser address-bar and replace it with link_of_the_webpage.
- Say, the downloaded webpages’ name is downloaded_webpage.html. Now, use the following command to convert it into PDF:
wkhtmltopdf downloaded_webpage.html give_it_any_name_you_want.pdf
This should convert your webpage into a PDF file.