How to Install wkhtmltopdf on cPanel/ Centos Server


wkhtmltopdf is an open-source command-line tool to convert HTML into PDF. It is widely used by applications to generate invoices and other pdf documents. for example, a python or PHP script will use it through its respective shell command to convert any URL to a PDF.

The use is very easy, simple call wkhtmltopdf from the terminal with source URL and destination pdf name. for example

If you want to capture a google doodle (whenever there is) you can the command will be

 

wkhtmltopdf http://google.com mydoodle.pdf

or want to keep the current version of Twitter to save your trending tweets records,

wkhtmltopdf http://twitter.com mytweets.pdf

Installing wkhtmltopdf  on cPanel

Installation is pretty straight forward as would any rpm package.

  1. Download

    Download the appropriate version from https://wkhtmltopdf.org/downloads.html. For sake of this article, our server is running centOS 7.9 with cPanel version v92.0.5. Please note that all downloads are currently on GitHub, so you can also browse for a specific download from there or use the links below. There are many other sources that you can found by googling it, but as a rule of thumb always go for an official source.The package also includes wkhtmltoimage (used to convert any webpage/ URL to a number of image formats) sources and hence is named as wkhtmltox

  2. wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.centos7.x86_64.rpm
    --2020-12-19 10:52:56-- https://github.com/wkhtmltopdf/packaging/releases/downl oad/0.12.6-1/wkhtmltox-0.12.6-1.centos7.x86_64.rpm
    Resolving github.com (github.com)... 140.82.121.3
    Connecting to github.com (github.com)|140.82.121.3|:443... connected.
    HTTP request sent, awaiting response... 302 Found
    Resolving github-production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com)... 52.217.45.44
    Connecting to github-production-release-asset-2e65be.s3.amazonaws.com (github-pr oduction-release-asset-2e65be.s3.amazonaws.com)|52.217.45.44|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 14071376 (13M) [application/octet-stream]
    Saving to: ‘wkhtmltox-0.12.6-1.centos7.x86_64.rpm’100%[======================================>] 14,071,376 10.8MB/s in 1.2s2020-12-19 10:52:58 (10.8 MB/s) - ‘wkhtmltox-0.12.6-1.centos7.x86_64.rpm’ saved [14071376/14071376]
  3. Install

    To install wkhtmltopdf RPM that we just downloaded, use the following command

    sudo rpm -i wkhtmltox-0.12.6-1.centos7.x86_64.rpm

    The -i switch is of course instructing rpm to install the package

    Or alternately you can use yum package manager, use the following command with localinstall option, instructing yum to look within the current directory for wkhtmltox RPMsudo yum localinstall wkhtmltox-0.12.6-1.centos7.x86_64.rpm

  4. Test

    Test executable while converting the homepage of cpanelplesk.com into pdf. On WHM/cPanel terminal window or on SSH console use following command

    wkhtmltopdf https://cpanelplesk.com my-favorate-webhosting-blog.pdf
    
    Loading pages (1/6)
    Counting pages (2/6)
    Resolving links (4/6)
    Loading headers and footers (5/6)
    Printing pages (6/6)
    Done
    

and wooha, Its all done

The .htaccess is a hidden text file that contains some additional configuration for the websites hosted on an apache server, and it can directly affect how your website behaves in certain situations. By using .htaccess, you can rewrite the URL, Redirect your website. Password-protect your directories and disable access from a spec