Are you looking for command line tools to help you render web pages to PDF or to an image?. wkhtmltopdf and wkhtmltoimage are open source tools created to be used in a command line interface which makes them fit for integration to other applications. If you’re on a Cloud platform such as AWS, you can create serverless Lambda functions to aid in conversion processing with wkhtmltopdf & wkhtmltoimage.
To install wkhtmltopdf & wkhtmltoimage command line tools on Amazon Linux 2 server you’ve to download the RPM package then use yum package manager to install it on Amazon Linux 2 system.
First install wget downloader:
sudo yum -y install wget
Once you have wget command line tool use it to pull the latest wkhtmltopdf RPM package:
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.amazonlinux2.x86_64.rpm
Install the tool with yum:
sudo yum install ./wkhtmltox-0.12.6-1.amazonlinux2.x86_64.rpm
You will be prompted to accept the installation by pressing the y key in your command:
Dependencies Resolved
==================================================================================================================================================================
Package Arch Version Repository Size
==================================================================================================================================================================
Installing:
wkhtmltox x86_64 1:0.12.6-1.amazonlinux2 /wkhtmltox-0.12.6-1.amazonlinux2.x86_64 118 M
Installing for dependencies:
xorg-x11-fonts-75dpi noarch 7.5-9.amzn2 amzn2-core 2.8 M
Transaction Summary
==================================================================================================================================================================
Install 1 Package (+1 Dependent package)
Total size: 121 M
Total download size: 2.8 M
Installed size: 121 M
Is this ok [y/d/N]: y
To check release version of wkhtmltopdf use the commands below.
$ wkhtmltopdf --version
wkhtmltopdf 0.12.6 (with patched qt)
The same applies for wkhtmltoimage:
$ wkhtmltoimage --version
wkhtmltoimage 0.12.6 (with patched qt)
Usage help pages can be checked with –help command options.
$ wkhtmltoimage --help
Name:
wkhtmltoimage 0.12.6 (with patched qt)
Synopsis:
wkhtmltoimage [OPTIONS]...
See all usage command options and flags for wkhtmltopdf:
$ wkhtmltopdf --help
You can now start using wkhtmltopdf and wkhtmltopdf tools on your Amazon Linux 2 machine.
If you get Error wkhtmltopdf: error while loading shared libraries: libpng16.so.16: cannot open shared object file: No such file or directory. then check out our article here Fix error loading shared libraries: libpng16.so.16: cannot open shared object file