Install wkhtmltopdf & wkhtmltoimage on Amazon Linux 2

Posted on 248 views

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 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]...  

Description:
  Converts an HTML page into an image,

General Options:
      --crop-h                   Set height for cropping
      --crop-w                   Set width for cropping
      --crop-x                   Set x coordinate for cropping
      --crop-y                   Set y coordinate for cropping
  -H, --extended-help                 Display more extensive help, detailing
                                      less common command switches
  -f, --format                Output file format
      --height                   Set screen height (default is calculated
                                      from page content) (default 0)
  -h, --help                          Display help
      --license                       Output license information and exit
      --log-level              Set log level to: none, error, warn or
                                      info (default info)
      --quality                  Output image quality (between 0 and 100)
                                      (default 94)
  -q, --quiet                         Be less verbose, maintained for backwards
                                      compatibility; Same as using --log-level
                                      none
  -V, --version                       Output version information and exit
      --width                    Set screen width, note that this is used
                                      only as a guide line. Use
                                      --disable-smart-width to make it strict.
                                      (default 1024)

Contact:
  If you experience bugs or want to request new features please visit
  

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

 

coffee

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.