How To: Install wkhtmltopdf on Amazon Linux

The other day I was optimizing a reporting engine and needed a quick and easy way to generate PDFs from HTML templates. There are several options out there, but after some research, I decided to use wkhtmltopdf ( It then took me a few hours of scouring the Internet to find the appropriate steps to install it on Amazon Linux. I kept running into a series of problems with the version, required libraries, and font kerning. Some trial and error, and help from some others, finally got me up and running. Here’s what worked for me.

1. Download the Linux (CentOS 6) 64-bit version from to your Amazon Linux instance (the /tmp directory is fine). Please note that the Linux (CentOS 7) version was not compatible with the latest Amazon Linux build.

2.  Install the newly download package.

This may require the installation of some dependencies (e.g. xorg-x11-fonts-75dpi.noarch 0:7.2-9.1.5.amzn1). Just accept.

3. Try running wkhtmltopdf.

4. If you get the following: “error while loading shared libraries: cannot open shared object file: No such file or directory”, you may need to download and build the libpng library. I don’t think you should get this with the CentOS 6 version, but if you do, ping me in the comments.

5. If you don’t get an error, then you should have a nicely formatted PDF waiting for you. However, you’ll probably notice that the kerning is off on some of the text.

For example:

Bad Kerning Example

Notice how the “ng” in “doing” and the “la” and “ly” in “lately” are too close to one another. There is a quick fix for this that I found on wkhtmltopdf’s github page: You kind of have to dig for it, so here it is:

So now when you run it you should get something like this:

Proper font kerning

This looks much better.

And that’s it. Hope this saves you some time.

Update: The link to download the Linux (CentOS 6) 64-bit version has been updated thanks to Hannah and Andrew.

Tags: , , , ,

Did you like this post? 👍  Do you want more? 🙌  Follow me on Twitter or check out some of the projects I’m working on.

29 thoughts on “How To: Install wkhtmltopdf on Amazon Linux”

  1. Thanks for this Jeremy – this is the only article I found that actually provides clear instructions on how to install on Amazon Linux machines. Got it up and working in no time after reading this – good stuff!

  2. I’m so glad I found this post – saved us about a days worth of compiling time! Our mistake was we were trying CentOS7 to start with – and it just didn’t work on AWS. CentOS6 went through with no problems

  3. An alternative is to create a /.ebextensions/myappsname.config file, containing:

    xorg-x11-fonts-75dpi: []
    fontconfig: []
    freetype: []

    The advantage is that wkhtmltopdf will be automatically installed in each new instance you spawn. In other words, you get to keep the elasticity that you’d expect from cloud services.

    1. Actually, that wouldn’t be right because rpm installations are done before yum, so the dependencies are not met yet. Here’s a better version:

  4. Hi jeremy.
    i am getting error “wkhtmltopdf: error while loading shared libraries: cannot open shared object file: No such file or directory” on amazon centos. i also tried installing libpng15 on /usr/lib. but still it is unsolved.
    thanks in advance. any help appreciated.

    1. Vinay,

      Sorry for the late reply. If you’re still having a problem, try this:

      sudo yum install xorg-x11-fonts-100dpi.noarch xorg-x11-fonts-75dpi.noarch xorg-x11-fonts-ISO8859-1-100dpi.noarch xorg-x11-fonts-ISO8859-1-75dpi.noarch xorg-x11-fonts-ISO8859-14-100dpi.noarch xorg-x11-fonts-ISO8859-14-75dpi.noarch xorg-x11-fonts-ISO8859-15-100dpi.noarch xorg-x11-fonts-ISO8859-15-75dpi.noarch xorg-x11-fonts-ISO8859-2-100dpi.noarch xorg-x11-fonts-ISO8859-2-75dpi.noarch xorg-x11-fonts-ISO8859-9-100dpi.noarch xorg-x11-fonts-ISO8859-9-75dpi.noarch xorg-x11-fonts-Type1.noarch xorg-x11-fonts-cyrillic.noarch xorg-x11-fonts-ethiopic.noarch xorg-x11-fonts-misc.noarch

      Then Download:

      And run:
      tar -zxvf libpng-1.5.15.tar.gz


      Then finally:
      sudo make install

      Hope that helps.

  5. Thank you very much for this! I was trying to install it in Amazon AMI and it was flawless. It had to download xorg-x11-fonts-75 dpi but it worked fine.

    I have a question though, if there is a new version released what would be the procedure to udpate the library?

    Thank you again and best regards.

  6. And finally, I found another method that may also be a good option.

    In my case, I needed wkhtmltopdf for a Symfony project, and it turns out you can also install wkhtml2pdf using composer.

    Here is the address where I found out how to do it. You need to download the library via composer and then update the config file of knp_snappy to load the lib from the vendor directory.

  7. if people/author is alive the can you assist how can I install wkhtmltopdf in 2019 in amzon linux of amzone console vm ? above links or steps doesnt work for me

  8. Hi Jeremy,
    This is very helpful, thank you. Could you provide steps/recommendations to download and build the latest libpng library on Amazon Linux 2 so that more recent versions of wkhtmltopdf can be used?

  9. Hi Jeremy,

    Great Job! I have a question. I have installed wkhtmltopdf as you said and seems be good. So, I have a problem with page with javascript charts as google charts for example. The javascripts charts in the pdf are not appears. Only the text and statics images work fine. I have tried with –javascript-delay parameter but it’s the same. Do you have any idea about wkhtmltopdf and javascript charts as google or chartjs for example?

    Example link:

    Amazon Linux AMI 2018.03

    Thanks a lot for your help!

Leave a Reply

Your email address will not be published. Required fields are marked *

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