How to convert html pages to pdf using wkhtml2pdf

Information TechnologyLinux

This article will guide you to install a tool which can convert your HTML pages or HTML output to PDF format. This feature will also be helpful to write a code for generating Pdf’s, if we need to send them to a group of customers or clients and for sending reports instead of HTML (which you can send them via emails in PDF format) that will be a value addition to your software.

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

Need to install some required fonts which are used for wkhtmltopdf

# yum install -y xorg-x11-fonts-75dpi
# yum install -y xorg-x11-fonts-Type1

To get the file, please run the following

# wget https://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.10.0_rc2-static-amd64.tar.bz2

To extract the files –

# tar -xvzf wkhtmltopdf-0.10.0_rc2-static-amd64.tar.bz2 -C /opt
# cd /opt
# mv wkhtmltopdf-amd64 wkhtmltopdf
# mv wkhtmltopdf /usr/local/bin

To convert any HTML web page to PDF, run the following example command. It will convert the given web pages to install-eclipse .pdf as as output to /opt directory.

# wkhtmltopdf http://google.com/ /opt/google.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

After this installation, as mentioned earlier, now you really want a homepage and want to save it as a PDF, then you could use Wkhtmltopdf for that. Seriously, you could use it to generate invoices and save or send, create birthday cards and send them or save them or all other sorts of fun things.

Just use your imagination! That we can save any web pages or html page into PDF format for further use.

raja
Published on 18-Oct-2019 16:24:37
Advertisements