Home Blog How to install WKHTMLTOPDF in Ubuntu via Script?
How to install WKHTMLTOPDF in Ubuntu via Script?

How to Install WKHTMLTOPDF in Ubuntu via Script?

What is WKHTMLTOPDF?

wkhtmltopdf and wkhtmltoimage are two open source( LGPLv3) command line tools which are used to render HTML into PDF and  colourful image formats using the Qt WebKit rendering machine. These commands run entirely" headless" and don't bear a display or display service. 

How can we use wkhtmltopdf in odoo?

Odoo will render the PDF by using wkhtmltopdf, so if you are writing the code to get the PDF report from odoo then the  wkhtmltopdf is mandatory. If you don’t have it installed on the server then odoo will give you a warning and will not download any PDF report and the reports will get opened in HTML format only.

#!/bin/bash
#########################################################################
# Script for installing WKHTMLTOPDF on Ubuntu
# Author: Kanak Infosystems LLP.
# Reference: https://raw.githubusercontent.com/Yenthe666/InstallScript/16.0/odoo_install.sh

# Make a new file:
# sudo nano wkhtmltopdf-install.sh
# Place this content in it and then make the file executable:
# sudo chmod +x wkhtmltopdf-install.sh
# Execute the script to install WKHTMLTOPDF:
# ./wkhtmltopdf-install
#########################################################################

if [[ $(lsb_release -r -s) == "22.04" ]]; then
    WKHTMLTOX_X64="https://packages.ubuntu.com/jammy/wkhtmltopdf"
    WKHTMLTOX_X32="https://packages.ubuntu.com/jammy/wkhtmltopdf"
    #No Same link works for both 64 and 32-bit on Ubuntu 22.04
else
    # For older versions of Ubuntu
    WKHTMLTOX_X64="https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.$(lsb_release -c -s)_amd64.deb"
    WKHTMLTOX_X32="https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.$(lsb_release -c -s)_i386.deb"
fi

echo -e "\n---- Update Server ----"
# universe package is for Ubuntu 18.x
sudo add-apt-repository universe
# libpng12-0 dependency for wkhtmltopdf for older Ubuntu versions
sudo add-apt-repository "deb http://mirrors.kernel.org/ubuntu/ xenial main"
sudo apt-get update
sudo apt-get upgrade -y

echo -e "\n---- Installing WKHTMLTOPDF ----"
if [ "`getconf LONG_BIT`" == "64" ];then
  _url=$WKHTMLTOX_X64
else
  _url=$WKHTMLTOX_X32
fi
sudo wget $_url

if [[ $(lsb_release -r -s) == "22.04" ]]; then
# Ubuntu 22.04 LTSConnecting MongoDB with NodeJs
sudo apt install wkhtmltopdf -y
else
  # For older versions of Ubuntu
sudo gdebi --n `basename $_url`
fi

sudo ln -s /usr/local/bin/wkhtmltopdf /usr/bin
sudo ln -s /usr/local/bin/wkhtmltoimage /usr/bin

Please Note: Before executing the script, you need to make sure that you completely understand what it does.

If you have any queries or need any assistance regarding Odoo, you can contact us, Kanak Infosystems LLP.

Get In Touch with Us

Leave a Comment

Your email address will not be published.

Submit
Your comment is under review by our moderation team.