On this article we will discuss how to install wkhtmltopdf on CentOS 7 and how to use it in a simple explanation. The wkhtmltopdf is a useful tools for transforming html page (web) to pdf document.
Let’s say, there was an urgent need to create a pdf document directly from a website, and the content must be the same as possible. So, at that time, we can imagine how complicated it would be if it was done manually. Starting from downloading content, determining the appropriate layout and storing it in pdf format, you can imagine how difficult it is.
But for Linux users, there are several tools that can be used easily and all of the above complexities can be resolved quickly. One suitable tool for this need is wkhtmltopdf which is available for free on its official website or on github. wkhtmltopdf is very useful and trustworthy solution for creating and storing snapshots of web pages in real-time.
wkhtmltopdf is an open source (LGPLv3) 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 and do not require a display or display service.
wkhtmltopdf Installation on Centos 7
The lates stable version of wkhtmltopdf is 0.12.5 and we can get it directly from github or wkhtmltopdf download page. At this article we will install wkhtmltopdf by using github source and using yum install command line.
[ramans@localhost ~]$ sudo yum install -y https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox-0.12.5-1.centos7.x86_64.rpm
the output will be as follow :
==================================================================================================================== Package Arch Version Repository Size Installing: wkhtmltox x86_64 1:0.12.5-1.centos7 /wkhtmltox-0.12.5-1.centos7.x86_64 113 M Installing for dependencies: xorg-x11-fonts-75dpi noarch 7.5-9.el7 base 2.8 M Transaction Summary Install 1 Package (+1 Dependent package) Total size: 116 M Total download size: 2.8 M Installed size: 116 M Downloading packages: xorg-x11-fonts-75dpi-7.5-9.el7.noarch.rpm | 2.8 MB 00:02:23 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : xorg-x11-fonts-75dpi-7.5-9.el7.noarch 1/2 Installing : 1:wkhtmltox-0.12.5-1.centos7.x86_64 2/2 Verifying : 1:wkhtmltox-0.12.5-1.centos7.x86_64 1/2 Verifying : xorg-x11-fonts-75dpi-7.5-9.el7.noarch 2/2 Installed: wkhtmltox.x86_64 1:0.12.5-1.centos7 Dependency Installed: xorg-x11-fonts-75dpi.noarch 0:7.5-9.el7 Complete!
After the installation was completed, we could verify its version by submitting command : (the version is 0.12.5).
[ramans@localhost ~]$ wkhtmltopdf --version wkhtmltopdf 0.12.5 (with patched qt)
How To Use wkhtmltopdf (on Centos 7)
Showing wkhtmltopdf in action is better if we are using example. At this case, I will convert the page of http://otodiginet.com/database/how-to-install-mongodb-on-centos-7/ to be a pdf document. Here are the steps. I will use my home directory as
(/home/ramans) as pdf document destination.
[ramans@localhost ~]$ wkhtmltopdf http://otodiginet.com/database/how-to-install-mongodb-on-centos-7 wkhtmltopdf_test01.pdf
Its mean if we are going to save and convert
http://otodiginet.com/database/how-to-install-mongodb-on-centos-7 web page to
wkhtmltopdf_test01.pdf document. The result well be found at ramans home directory. And we can verify the file by submitting command.
[ramans@localhost ~]$ file wkhtmltopdf_test01.pdf [ramans@localhost ~]$ pdfinfo wkhtmltopdf_test01.pdf
For viewing the pdf document we will use the
evince tools. By submitting the command as shown below :
[ramans@localhost ~]$ evince wkhtmltopdf_test01.pdf
The document can be seen as below :
The wkhtmltopdf is a useful tools for save and convert HTML document (web page) to pdf document. The wkhtmltopdf installation process is very simple and easy. I recommend this tools to be installed on your system. For open the pdf document we use pdf reader, at this case we use the evince.