TUTORIAL Working With Wkhtmltopdf

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

 


OPEN SOURCE  41

Wkhtmltopdf – A Smart Tool to Convert Website HTML Page to PDF in Linux


by Ravi Saive | Published: January 28, 2017 | Last Updated: July 26, 2017

 Download Your Free eBooks NOW - 10 Free Linux eBooks for Administrators | 4 Free Shell Scripting eBooks

Wkhtmltopdf is an open source simple and much effective command-line shell utility that enables user to convert any given HTML (Web Page) to PDF
document or an image (jpg, png, etc).

Wkhtmltopdf is written in C++ programming language and distributed under GNU/GPL (General Public License). It uses WebKit rendering layout
engine to convert HTML pages to PDF document without loosing the quality of the pages. Its is really very useful and trustworthy solution for creating
and storing snapshots of web pages in real-time.

Wkhtmltopdf Features
Open source and cross platform.
Convert any HTML web pages to PDF files using WebKit engine.
Options to add headers and footers
Table of Content (TOC) generation option.
Provides batch mode conversions.
Support for PHP or Python via bindings to libwkhtmltox.

In this article we will show you how to install Wkhtmltopdf program under Linux systems using source tarball files.

Install Evince (PDF Viewer)


Let’s install evince (a PDF reader) program for viewing PDF files in Linux systems.

$ sudo yum install evince [RHEL/CentOS and Fedora]


$ sudo dnf install evince [On Fedora 22+ versions]
$ sudo apt-get install evince [On Debian/Ubuntu systems]
Download Wkhtmltopdf Source File

Download wkhtmltopdf source files for your Linux architecture using Wget command, or you can also download latest versions (current stable series
is 0.12.4) at wkhtmltopdf download page.

On 64-bit Linux OS

$ wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_
linux-generic-amd64.tar.xz

On 32-bit Linux OS

$ wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_
linux-generic-i386.tar.xz

Install Wkhtmltopdf in Linux


Extract the files to a current working directory using following tar command.

------ On 64-bit Linux OS ------


$ sudo tar -xvf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz

------ On 32-bit Linux OS ------


$ sudo tar -xvzf wkhtmltox-0.12.4_linux-generic-i386.tar.xz

Install the wkhtmltopdf under /usr/bin directory for easy execution of program from any path.

$ sudo cp wkhtmltox/bin/wkhtmltopdf /usr/bin/

How to Use Wkhtmltopdf?


Here we will see how to covert remote HTML pages to PDF files, verify information, view created files using evince program from the GNOME
Desktop.

Convert Website HTML Page to PDF File


To convert any website HTML web page to PDF, run the following example command. It will convert the given webpage to 10-Sudo-
Configurations.pdf in current working directory.

# wkhtmltopdf https://www.tecmint.com/sudoers-configurations-for-setting-sudo-in-linux/ 10-S


udo-Configurations.pdf

Sample Output :
Loading pages (1/6)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done

View Generated PDF File


To verify that the file is created, use the following command.

$ file 10-Sudo-Configurations.pdf

Sample Output :

10-Sudo-Configurations.pdf: PDF document, version 1.4

View Information of Generated PDF File


To view the information of generated file, issue the following command.

$ pdfinfo 10-Sudo-Configurations.pdf

Sample Output :

Title: 10 Useful Sudoers Configurations for Setting 'sudo' in Linux


Creator: wkhtmltopdf 0.12.4
Producer: Qt 4.8.7
CreationDate: Sat Jan 28 13:02:58 2017
Tagged: no
UserProperties: no
Suspects: no
Form: none
JavaScript: no
Pages: 13
Encrypted: no
Page size: 595 x 842 pts (A4)
Page rot: 0
File size: 697827 bytes
Optimized: no
PDF version: 1.4

View Created PDF File


Take a look at the newly created PDF file using evince program from the desktop.
$ evince 10-Sudo-Configurations.pdf

Sample Screenshot :
Looks pretty nice under my Linux Mint 17 box.

View Website Page in PDF

Create TOC (Table Of Content) of a Page to PDF


To create a table of content for a PDF file, use the option as toc.

$ wkhtmltopdf toc https://www.tecmint.com/sudoers-configurations-for-setting-sudo-in-linux/


10-Sudo-Configurations.pdf
Sample Output :

Loading pages (1/6)


Counting pages (2/6)
Loading TOC (3/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done

To check the TOC for the created file, again use evince program.

$ evince 10-Sudo-Configurations.pdf

Sample Screenshot :
Take a look at the picture below. it looks even more better than the above.
Create Website Page to Table of Contents in PDF

Wkhtmltopdf Options and Usage


For Wkhtmltopdf more usage and options, use the following help command. It will display list of all available options that you can use with it.

$ wkhtmltopdf --help

SHARE
+ +
 
Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:


1. Stay Connected to: Twitter | Facebook | Google Plus

2. Subscribe to our email updates: Sign Up Now


3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
4. Become a Supporter - Make a contribution via PayPal

5. Support us by purchasing our premium books in PDF format.


6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Tags: HTML to PDF

Ravi Saive View all Posts


I am Ravi Saive, creator of TecMint. A Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My
 Servers runs on Open Source Platform called Linux. Follow Me: Twitter, Facebook and Google+

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.
NEXT STORY
5 Reasons To Install Linux Today 

PREVIOUS STORY
 Min – A Lighter, Faster and Secure Web Browser for Linux

 YOU MAY ALSO LIKE...

 21  16

RainLoop Webmail – A Modern Fast Web Based Email Client for Linux How to Install and Run VLC Media Player as Root in Linux

14 MAR, 2014 28 APR, 2017

41 RESPONSES

 Comments 3  Pingbacks 0

jesse bautista  December 24, 2018 at 12:40 pm


I agree with John. I would say the best option ( or my advise should I say ) is to use PDFmyURL.com Two reasons: API’s are well
documented and easy to use, and the Pricing will not burn a hole in your wallet. Check their website at PDFmyURL.com and check it
yourselves. Awesome stuff.
Reply

Johm  September 4, 2018 at 6:40 pm


Nice on the paper but very bad in practice, unable to print more than 10 urls …
Reply

Hayat  February 8, 2018 at 2:32 pm


Hello Folks,
I was quite happily using wkhtmltopdf until this awesome library failed to convert anything from website. I don’t know how and why.
Please do check and update whats wrong here.
Reply

« Older Comments

GOT SOMETHING TO SAY? JOIN THE DISCUSSION.


Comment

Name * Email *

Website

Save my name, email, and website in this browser for the next time I comment.

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Post Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed .

I  TecMint :     

 BEGINNER'S GUIDE FOR LINUX  Start learning Linux in minutes 

 Vi/Vim Editor BEGINNER'S GUIDE  Learn vi/vim as a Full Text Editor 

 Linux Foundation Certification  Exam Study Guide to LFCS and LFCE


 

How to Add Linux Host to Nagios Monitoring Server Using NRPE Plugin

How to Install Nagios 4.3.4 on RHEL, CentOS and Fedora

Install Cacti (Network Monitoring) on RHEL/CentOS 7.x/6.x/5.x and Fedora 24-12

How to Install Google Chrome 75 On RHEL/CentOS 7 and Fedora 30

How to Install Ubuntu Alongside With Windows 10 or 8 in Dual-Boot

BARRYKANE SAYS:
I use Allavsoft to download YouTube to MP4, MP3, WAV, etc

RAVI SAIVE SAYS:


@KtalyN, Yes, I have updated the modification in...

RAVI SAIVE SAYS:


@Annihilannic, Thanks, I have corrected the location of...

RAVI SAIVE SAYS:


@Alex, Thanks for pointing out that error, it...

RAVI SAIVE SAYS:


@Shaikh, You can check our Linux services here: https://www.fosswork.com

Linux System Administrator Bundle with 7-Courses (96% off)

Add to Cart - $69


 Ending In: 3 days

Computer Hacker Professional Certification Course (96% Off)


Add to Cart - $59
 Ending In: 4 days

LINUX EBOOKS

Introducing Learn Linux In One Week and Go from Zero to Hero


RedHat RHCE/RHCSA Certification Preparation Guide
Linux Foundations LFCS/LFCE Certification Guide
Postfix Mail Server Setup Guide for Linux
Ansible Setup Guide for Linux
Django Setup Guide for Linux
Awk Getting Started Guide for Beginners
Citrix XenServer Setup Guide for Linux

    

Never Miss Any Linux Tutorials, Guides, Tips and Free eBooks
Join Our Community Of 150,000+ Linux Lovers and get a weekly newsletter in your inbox

YES! SIGN ME UP

LINUX MONITORING TOOLS

Iotop – Monitor Linux Disk I/O Activity and Usage Per-Process Basis

How to Install and Configure ‘Collectd’ and ‘Collectd-Web’ to Monitor Server Resources in Linux

How to Install Cacti with Cacti-Spine in Debian and Ubuntu

13 Linux Network Configuration and Troubleshooting Commands


16 Useful Bandwidth Monitoring Tools to Analyze Network Usage in Linux

LINUX INTERVIEW QUESTIONS

11 Basic Linux Interview Questions and Answers

10 Useful ‘ls’ Command Interview Questions – Part 2

Nishita Agarwal Shares Her Interview Experience on Linux ‘iptables’ Firewall

Practical Interview Questions and Answers on Linux Shell Scripting

10 Linux Interview Questions and Answers for Linux Beginners – Part 3

OPEN SOURCE TOOLS

9 Tools to Monitor Linux Disk Partitions and Usage in Linux

6 Best Email Clients for Linux Systems

10 Top Open Source Artificial Intelligence Tools for Linux

Best IP Address Management Tools for Linux

My Favorite Command Line Editors for Linux – What’s Your Editor?



Tecmint: Linux Howtos, Tutorials & Guides © 2019. All Rights Reserved.
The material in this site cannot be republished either online or offline, without our permission.
Hosting Sponsored by : Linode Cloud Hosting

    

You might also like