67

I have tried in all ways to get wkhtmltopdf installed on our web server but unfortunately it is not getting installed. I cannot access user/bin folder as stated in a tutorial on installation.

On the server in public_html folder there is a sub folder _vti_bin, I copied the file wkhtmltopdf-i386 from wkhtmltopdf-0.9.1-static-i386, but I am not able to execute it.

How to install wkhtmltopdf on (shared hosting) web server and get it working?

HEDMON
  • 727
  • 10
  • 24
Yogi Yang 007
  • 5,147
  • 10
  • 56
  • 77

12 Answers12

52

I've managed to successfully install wkhtmltopdf-amd64 on my shared hosting account without root access.

Here's what i did:

Downloaded the relevant static binary v0.10.0 from here: http://code.google.com/p/wkhtmltopdf/downloads/list

EDIT: The above has moved to here

via ssh on my shared host typed the following:

$ wget {relavant url to binary from link above}
$ tar -xvf {filename of above wget'd file}

you'll then have the binary on your host and will be able to run it regardless of if its in the /usr/bin/ folder or not. (or at least i was able to)

To test:

$ ./wkhtmltopdf-amd64 http://www.example.com example.pdf
  • Note remember that if you're in the folder in which the executable is, you should probably preface it with ./ just to be sure.

Worked for me anyway

Christopher
  • 1,358
  • 17
  • 32
  • 1
    This worked for me as well. I had to install LZMA util http://tukaani.org/lzma/ since tar version on my shared host did not support .lzma archive. – understack Oct 21 '10 at 18:10
  • 2
    For the people tuning in at this point, the tars are now bzipped (.bz2). You can unpack them with `bunzip2 {filename}` – Joel Peltonen Aug 15 '12 at 14:59
  • @Christopher, I'm on a shared server, can't install. So I uploaded and uncompressed via c-panel, right to my current folder, and ran wkhtmltopdf-amd64 straight away with no paths etc. I get the error: "sh: wkhtmltopdf-amd64: command not found". Any ideas? On c-panel file manager, it says the file type is text/x-generic, if that means anything. – user961627 Sep 02 '12 at 10:00
  • Never mind, I got it to work! :) Just needed to remember I'm on Linux and refer to it as "./wkhtmltopdf" instead of "wkhtmltopdf". – user961627 Sep 02 '12 at 10:43
  • Added new link in answer, but to be honest, it is signposted that they're moved and we cant keep updating links, the answer still stands on its own. – Christopher Mar 07 '14 at 22:52
  • Great solution but wkhtmltopdf is now a .deb file, and I'm not sure how to perform the same operation. I've been trying dpkg -x filename, but it doesn't seem to work. Any suggestions? – mtpultz Nov 29 '14 at 21:41
  • @mtpultz: that is covered in the [download FAQ](http://wkhtmltopdf.org/downloads.html#faq) -- see this [post on the mailing list](https://groups.google.com/d/msg/wkhtmltopdf-general/5gPvvd9bgRo/wI4RmGA0dIsJ). – ashkulz Jan 26 '15 at 07:27
  • Whether you will be allowed to do https://www.cyberciti.biz/faq/debian-ubuntu-linux-wkhtmltopdf-error-while-loading-shared-libraries-libxrender-so-1/ on a hosted site is unclear - but otherwise you might have luck convince the hosting partner to do the `ldd`and install parts for you, YMMV :$ – walt_die Jun 08 '19 at 20:50
36

If you have sudo access...

Ubuntu 14.04 / 15.04 / 18.04:

sudo apt-get install wkhtmltopdf
# or
sudo apt install wkhtmltopdf

Others

Look at the other answers.

Community
  • 1
  • 1
jmunsch
  • 22,771
  • 11
  • 93
  • 114
  • 3
    `sudo yum install wkhtmltopdf` worked for me, for those of us on Others. – MECU Feb 12 '16 at 22:11
  • 4
    `sudo yum install wkhtmltopdf` dosen't work. Getting 'No package wkhtmltopdf available.' – Ninz Feb 22 '16 at 11:35
  • what's the equivalent for `apt-get update` but for `yum`? – jmunsch Feb 22 '16 at 15:27
  • 1
    This doesn't really answer the OP's question, since they were on shared hosting - they very likely don't have sudo permissions and almost certainly don't have the ability to install new software via package managers (on most shared hosting options, anyway). – bsplosion Aug 05 '19 at 16:35
27

If its ubuntu then go ahead with this, already tested.:--

first, installing dependencies

sudo aptitude install openssl build-essential xorg libssl-dev

for 64bits OS

wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2 
tar xvjf wkhtmltopdf-0.9.9-static-amd64.tar.bz2
mv wkhtmltopdf-amd64 /usr/local/bin/wkhtmltopdf
chmod +x /usr/local/bin/wkhtmltopdf

for 32bits OS

wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-i386.tar.bz2 
tar xvjf wkhtmltopdf-0.9.9-static-i386.tar.bz2
 mv wkhtmltopdf-i386 /usr/local/bin/wkhtmltopdf
chmod +x /usr/local/bin/wkhtmltopdf
Mohit Jain
  • 43,139
  • 57
  • 169
  • 274
  • Thanks for your tips. But we are hosting on shared servers and there we are not allowed to install anything. – Yogi Yang 007 Apr 27 '11 at 15:47
  • @Yogi Yang 007 even on shared host u can ask for shell access. I tried on bluehost. I dont know its legal or not. :-) – Mohit Jain May 03 '11 at 05:39
  • Worked for me running an Ubuntu virtual machine server using Vagrant. Thanks, Mohit! – RoboBear Jan 01 '16 at 23:25
  • 2
    Worked for me on Ubuntu 14.04, just be careful : the recent versions on the website are now in .tar.xz, use `tar -xvf` to unpack the files. – Leogout Mar 20 '16 at 11:07
4

Debian 8 Jessie
This works sudo apt-get install wkhtmltopdf

Artem Mostyaev
  • 3,874
  • 10
  • 53
  • 60
4

Latest update for CentOS:

  • sudo yum install -y libpng libjpeg openssl icu libX11 libXext libXrender xorg-x11-fonts-Type1 xorg-x11-fonts-75dpi
  • wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
  • tar -xvf wkhtmltox-0.12.4_linux-generic-amd64.tar
  • sudo mv wkhtmltox/bin/* /usr/local/bin/
  • check installation success: wkhtmltopdf -V
  • rm -rf wkhtmltox
  • rm -f wkhtmltox-0.12.4_linux-generic-amd64.tar
SV125
  • 273
  • 1
  • 3
  • 13
3

Chances are that without full access to this server (due to being a hosted account) you are going to have problems. I would go so far as to say that I think it is a fruitless endeavor--they have to lock servers down in hosted environments for good reason.

Call your hosting company and make the request to them to install it, but don't expect a good response--they typically won't install very custom items for single users unless there is a really good reason (bug fixes for example).

Lastly, depending on how familiar you are with server administration and what you are paying for server hosting now consider something like http://www.slicehost.com. $20 a month will get you a low grade web server (256 ram) and you can install anything you want. However, if you are running multiple sites or have heavy load the cost will go up as you need larger servers.

GL!

Shane
  • 16,779
  • 5
  • 27
  • 46
1

Place the wkhtmltopdf executable on the server and chmod it +x.

Create an executable shell script wrap.sh containing:

#!/bin/sh
export HOME="$PWD"
export LD_LIBRARY_PATH="$PWD/lib/"
exec $@ 2>/dev/null
#exec $@ 2>&1 # debug mode

Download needed shared objects for that architecture and place them an a folder named "lib":

  • lib/libfontconfig.so.1
  • lib/libfontconfig.so.1.3.0
  • lib/libfreetype.so.6
  • lib/libfreetype.so.6.3.18
  • lib/libX11.so.6 lib/libX11.so.6.2.0
  • lib/libXau.so.6 lib/libXau.so.6.0.0
  • lib/libxcb.so.1 lib/libxcb.so.1.0.0
  • lib/libxcb-xlib.so.0
  • lib/libxcb-xlib.so.0.0.0
  • lib/libXdmcp.so.6
  • lib/libXdmcp.so.6.0.0
  • lib/libXext.so.6 lib/libXext.so.6.4.0

(some of them are symlinks)

… and you're ready to go:

./wrap.sh ./wkhtmltopdf-amd64 --page-size A4 --disable-internal-links --disable-external-links "http://www.example.site/" out.pdf

If you experience font problems like squares for all the characters, define TrueType fonts explicitly:

@font-face {
  font-family:Trebuchet MS;
  font-style:normal;
  font-weight:normal;
  src:url("http://www.yourserver.tld/fonts/Trebuchet_MS.ttf");
  format(TrueType);
}
jockie
  • 19
  • 2
1

List of stable versions wkhtmltopdf: http://wkhtmltopdf.org/downloads.html

Installing wkhtmltopdf on Debian 8.2 (jessie) x64:

sudo apt-get install xfonts-75dpi
sudo apt-get install xfonts-base
sudo wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-jessie-amd64.deb
sudo dpkg -i wkhtmltox-0.12.2.1_linux-jessie-amd64.deb
Akairis
  • 407
  • 2
  • 11
1

Shared hosting no ssh or shell access?

Here is how i did it;

  1. Visit https://wkhtmltopdf.org/downloads.html and download the appropriate stable release for Linux. For my case I chose 32-bit which is wkhtmltox-0.12.4_linux-generic-i386.tar.xz
  2. Unzip to a folder on your local drive.
  3. Upload the folder to public_html (or whichever location fits your need) using an FTP program just like any other file(s)
  4. Change the binary paths in snappy.php file to point the appropriate files in the folder you just uploaded. Bingo! there you have it. You should be able to generate PDF files.
  • hi, this not work. get error : libXrender.so.1: cannot open shared object file: No such file or directory" }. how to fix it ? – Egi Nov 06 '17 at 05:45
  • @Chielarck Check whether you've downloaded for right architecture e.g 32bit. Also make you've included snappy dependencies in your project. – Kennedy Mwenda Nov 18 '17 at 13:47
  • can you give me direct link ? I've tried downloading. but nothing works – Egi Nov 22 '17 at 04:46
1

A few things have changed since the top answers were added. They used to work out for me, but not quite anymore, so I have been hacking around for a bit and came up with the following solution for Ubuntu 16.04. For Ubuntu 14.04, see the comment at the bottom of the answer. Apologies if this doesn't work for shared hosting, but it seems like this is the goto answer for wkhtmltopdf installation instructions in general.

# Install dependencies
apt-get install libfontconfig \
    zlib1g \
    libfreetype6 \
    libxrender1 \
    libxext6 \
    libx11-6

# TEMPORARY FIX! SEE: https://github.com/wkhtmltopdf/wkhtmltopdf/issues/3001
apt-get install libssl1.0.0=1.0.2g-1ubuntu4.8
apt-get install libssl-dev=1.0.2g-1ubuntu4.8

# Download, extract and move binary in place
curl -L -o wkhtmltopdf.tar.xz https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
tar -xf wkhtmltopdf.tar.xz
mv wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf
chmod +x /usr/local/bin/wkhtmltopdf

Test it out:

wkhtmltopdf http://www.google.com google.pdf

You should now have a file named google.pdf in the current working directory.

This approach downloads the binary from the website, meaning that you can use the latest version instead of relying on package managers to be updated.

Note that as of today, my solution includes a temporary fix to this bug. I realize that the solution is really not great, but hopefully it can be removed soon. Be sure to check the status of the linked GitHub issue to see if the fix is still necessary when you read this answer!

For Ubuntu 14.04, you will need to downgrade to a different version of libssl. You can find the versions here. Anyways, be sure to consider the implications of downgrading libssl before doing so on any production server.

I hope this helps someone!

ba0708
  • 10,180
  • 13
  • 67
  • 99
0

After trying, below command work for me

cd ~
yum install -y xorg-x11-fonts-75dpi xorg-x11-fonts-Type1 openssl git-core fontconfig
wget https://downloads.wkhtmltopdf.org/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
tar xvf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
mv wkhtmltox/bin/wkhtmlto* /usr/bin
Kirk Beard
  • 9,569
  • 12
  • 43
  • 47
  • thanks need to add sudo before mv after installing or got a permission error, worked for me –  Feb 13 '19 at 16:50
-1

Version 12.5 of wkhtmltopdf only lists DEB files on their download page now. Being a mac user and not knowing much linux or what DEB files were I couldn't use the solutions posted.

This page helped me get past the knew twist of downloading a DEB file: http://www.g-loaded.eu/2008/01/28/how-to-extract-rpm-or-deb-packages/

Basically what I did was:

  1. Downloaded from https://wkhtmltopdf.org/downloads.html
  2. Unzipped the DEB file.
  3. Unzipped data.tar.xz
  4. Uploaded the binary in the unzipped 'usr' folder from step 3 (usr/local/bin/wkhtmltopdf)

Then I found out that the 'exec' function was disabled on my host. So make sure you can specifically run 'exec' if you're using PHP to run this. "Can I run the wkhtmltopdf binary" isn't specific enough. My fault.

webhead
  • 99
  • 7