Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install wkhtmltopdf on Ubuntu (14.04 64-bit) or (16.04 64-bit)

Install wkhtmltopdf on Ubuntu

This was tested on:

  • Ubuntu 14.04 x64
  • Ubuntu 16.04 x64

Installation

sudo apt-get update
sudo apt-get install xvfb libfontconfig wkhtmltopdf

Test

Now it's time to test that everything is working as expected

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

If you see Done, then everything is installed correctly and you're ready to generate some PDF's :D

@mgomma

This comment has been minimized.

Copy link

@mgomma mgomma commented Jan 27, 2017

It returns -bash: /usr/bin/wkhtmltopdf: No such file or directory
Ubunut 16.04
Run that command fixed it to me sudo ln -s /usr/local/bin/wkhtmlto /usr/bin/wkhtmltopdf

@lsirluis

This comment has been minimized.

Copy link

@lsirluis lsirluis commented Apr 18, 2017

Thank!!!, thank you very much, 2 days trying to make wkhtmltopdf work in my vps without solution and in 2 minutes making this steps and its done!, thank you, greeting from colombia.

@marvoh

This comment has been minimized.

Copy link

@marvoh marvoh commented Apr 23, 2017

Thanks! This helped

@BryanTabarez

This comment has been minimized.

Copy link

@BryanTabarez BryanTabarez commented Apr 24, 2017

Why not from default ubuntu repositories?

sudo apt-get update
sudo apt-get install xvfb
sudo apt-get install wkhtmltopdf

(tested in ubuntu 14.04 x64)

@ramsesrom

This comment has been minimized.

Copy link

@ramsesrom ramsesrom commented May 25, 2017

root@mail:~# wkhtmltopdf http://www.google.com google.pdf Loading pages (1/6)
Segmentation fault ] 10%

what to do here?

@mridzuan

This comment has been minimized.

Copy link

@mridzuan mridzuan commented Jun 15, 2017

Please be informed that gna.org has been taken down.

@yusufyilmaz

This comment has been minimized.

Copy link

@yusufyilmaz yusufyilmaz commented Jun 29, 2017

Tested on a brand new Ubuntu 16.04 server. It throws an error
QXcbConnection: Could not connect to display

@zloynemec

This comment has been minimized.

Copy link

@zloynemec zloynemec commented Jun 29, 2017

@yusufyilmaz it works perfectly with the following command:
xvfb-run wkhtmltopdf http://google.com google.pdf

@Greentash

This comment has been minimized.

Copy link

@Greentash Greentash commented Jul 6, 2017

Thanks @brunogaspar, you make my day. Bigup yourself !!!
i was suffering by that install odoo 8

@dilab

This comment has been minimized.

Copy link

@dilab dilab commented Jul 17, 2017

This will not get you the latest version tho

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Aug 16, 2017

I am facing the following issue with my ubantu-16.04

Error: /bin/bash: wkhtmltopdf: command not found 

I used the which wkhtmltopdf command and got the following:

/usr/local/bin/wkhtmltopdf

And I also checked the $PATH variable using echo $PATH its giving the following output:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

How to fix this?

@agungjk

This comment has been minimized.

@aruprakshit

This comment has been minimized.

Copy link

@aruprakshit aruprakshit commented Oct 31, 2017

I am getting below error:

The switch --footer-right, is not support using unpatched qt, and will be ignored.The switch --footer-font-size, is not support using unpatched qt, and will be ignored.The switch --footer-center, is not support using unpatched qt, and will be ignored.The switch --header-html, is not support using unpatched qt, and will be ignored.The switch --header-spacing, is not support using unpatched qt, and will be ignored.The switch --footer-spacing, is not support using unpatched qt, and will be ignored.wkhtmltopdf: cannot connect to X server
Errno::EPIPE: Broken pipe

How to solve this?

@joshuapinter

This comment has been minimized.

Copy link

@joshuapinter joshuapinter commented Nov 14, 2017

Steps for install 0.12.3 on Ubuntu 16.04.

Because I wasted way too much time tracking this down, here is for others stumbling on this.

You don't want to use apt-get because it's out-of-date. I'm not a *nix expert but I have no idea why it takes so long for these updated packages to get pushed upstream to the repositories.

Just to help others, here is what my installation steps were installing 0.12.3 on Ubuntu 16.04:

cd ~
wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.3/wkhtmltox-0.12.3_linux-generic-amd64.tar.xz
tar vxf wkhtmltox-0.12.3_linux-generic-amd64.tar.xz 
cp wkhtmltox/bin/wk* /usr/local/bin/

And you can confirm with:

$ wkhtmltopdf --version
wkhtmltopdf 0.12.3 (with patched qt)

Btw, I chose 0.12.3 instead of 0.12.4 because of a strange page sizing issue, discussed here:

wkhtmltopdf/wkhtmltopdf#3226

@arriouach

This comment has been minimized.

Copy link

@arriouach arriouach commented Dec 3, 2017

Thanks, its helpful

@andrewduan

This comment has been minimized.

Copy link

@andrewduan andrewduan commented Dec 12, 2017

Hi @aruprakshit,
I am facing the same problem. have you found a way to solve the broken pipe issue?

@wlchn

This comment has been minimized.

Copy link

@wlchn wlchn commented Dec 27, 2017

@joshuapinter Thanks, its helpful, I chose 0.12.3 for same reason.

@ihr-it-projekt

This comment has been minimized.

Copy link

@ihr-it-projekt ihr-it-projekt commented Jan 4, 2018

@yusufyilmaz I have the same problem

QXcbConnection: Could not connect to display

Do you have a solution?

@vankov1

This comment has been minimized.

Copy link

@vankov1 vankov1 commented Jan 14, 2018

@ihr-it-projekt try using /usr/bin/xvfb-run /usr/bin/wkhtmltopdf (Check your path to wkhtmltopdf it can be /usr/local/bin/wkhtmltopdf)

@kai101

This comment has been minimized.

Copy link

@kai101 kai101 commented Jan 25, 2018

I have made a small deployment instruction here

https://gist.github.com/kai101/99d57462f2459245d28b4f5ea51aa7d0

@H1D1

This comment has been minimized.

Copy link

@H1D1 H1D1 commented Mar 6, 2018

retourner QXcbConnection: Could not connect to display

@saberanaibi

This comment has been minimized.

Copy link

@saberanaibi saberanaibi commented Mar 15, 2018

you have to be connected to the internet

@nitinnath

This comment has been minimized.

Copy link

@nitinnath nitinnath commented Mar 21, 2018

nice brother

@festusngor

This comment has been minimized.

Copy link

@festusngor festusngor commented Apr 19, 2018

See https://gist.github.com/srmds/2507aa3bcdb464085413c650fe42e31d for Installing wkhtmltopdf 0.12.4 on Ubuntu 16.04

@deivid11

This comment has been minimized.

Copy link

@deivid11 deivid11 commented Sep 6, 2018

Solution for QXcbConnection: Could not connect to display:
alias wkhtmltopdf='xvfb-run wkhtmltopdf'

@kunicmarko20

This comment has been minimized.

Copy link

@kunicmarko20 kunicmarko20 commented Sep 8, 2018

Thank you @deivid11

@damuz91

This comment has been minimized.

Copy link

@damuz91 damuz91 commented Oct 4, 2018

@Pedro75

This comment has been minimized.

Copy link

@Pedro75 Pedro75 commented Nov 15, 2018

When I test the result is :
wkhtmltopdf: cannot connect to X server
Installed on ubuntu 14.04
Anyone can help me?

@ajaychauhan727

This comment has been minimized.

Copy link

@ajaychauhan727 ajaychauhan727 commented Feb 18, 2019

@joshuapinter I followed your step to install it. Seems installed but i get following error while checking --version

wkhtmltopdf: error while loading shared libraries: libXrender.so.1: cannot open shared object file: No such file or directory

& to solve that I followed below link. Which makes it finally work proper.

https://www.cyberciti.biz/faq/debian-ubuntu-linux-wkhtmltopdf-error-while-loading-shared-libraries-libxrender-so-1/

@NaitikShah

This comment has been minimized.

Copy link

@NaitikShah NaitikShah commented Apr 22, 2019

Thanks, @brunogaspar it works!

@pvin

This comment has been minimized.

Copy link

@pvin pvin commented May 4, 2019

In production server (ubuntu 14.04) getting this error

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

/usr/local/rvm/gems/ruby-2.5.1/gems/wkhtmltopdf-binary-0.12.4/bin/wkhtmltopdf_linux_x86: 1: /usr/local/rvm/gems/ruby-2.5.1/gems/wkhtmltopdf-binary-0.12.4/bin/wkhtmltopdf_linux_x86: Syntax error: word unexpected (expecting ")")

Any help @brunogaspar @yusufyilmaz @brunogaspar

@brunogaspar

This comment has been minimized.

Copy link
Owner Author

@brunogaspar brunogaspar commented May 5, 2019

@pvin I've created 2 new servers to test one with Ubuntu 14.04 x64 and the other with Ubuntu 16.04 x64 and in both instances it worked as expected.

Try to reinstall wkhtmltopdf and see if that helps.

Sorry for not being of much help, but i'm unable to reproduce :(

@katiakweb

This comment has been minimized.

Copy link

@katiakweb katiakweb commented Jun 9, 2019

xvfb-run wkhtmltopdf http://google.com google.pdf

Thanks!!! This work for me!

@shamshi1988

This comment has been minimized.

Copy link

@shamshi1988 shamshi1988 commented Oct 16, 2019

@brunogaspar Thanks. It work's for me

@m4udSec

This comment has been minimized.

Copy link

@m4udSec m4udSec commented Dec 17, 2019

Solution for QXcbConnection: Could not connect to display:
alias wkhtmltopdf='xvfb-run wkhtmltopdf'

true story, blees u, mate !

@StevenMapes

This comment has been minimized.

Copy link

@StevenMapes StevenMapes commented Feb 2, 2020

Can anyone post updated instructions on how to get this working particularly when the PDF file uses resources loaded from https?

@anshu7k

This comment has been minimized.

Copy link

@anshu7k anshu7k commented Aug 7, 2020

I am using the latest version of wkhtmltopdf i.e 0.12.6. I am trying to convert an html using the command line, but it is gives me invalid pdf. but when i do the same procedure using wkhtmltopdf version 0.12.4, it works fine. I am not able to figure it out the reason, Am i missing something in the latest version?

wkhtmltopdf -s A2 --viewport-size 1280x1024 --orientation Landscape https://authlink-files-storage.ams3.digitaloceanspaces.com/authlink_prod/organization_docs/temp/doc_2020_07_31_00_00_a171ca5c669a4e81b9834ebbf844e89b a.pdf

@brunogaspar

This comment has been minimized.

Copy link
Owner Author

@brunogaspar brunogaspar commented Aug 7, 2020

Have you tried with version 0.12.5?

Have you checked their changelog https://github.com/wkhtmltopdf/wkhtmltopdf/blob/master/CHANGELOG.md for breaking changes or stuff that might not work by default?

@anshu7k

This comment has been minimized.

Copy link

@anshu7k anshu7k commented Aug 7, 2020

Yes i tried with 0.12.5 version too but that is also not working out for me. I am using ubuntu 18.04.
Only 0.12.4 is working. I dont know what is the issue.
Yes i checked official docs and github also but found nothing new

@brunogaspar

This comment has been minimized.

Copy link
Owner Author

@brunogaspar brunogaspar commented Aug 7, 2020

Then it's probably better to ask the authors for support or use something like StackOverflow to seek for help, that way you get help faster.

I personally don't use this anymore, so i can't really help much further.

@StevenMapes

This comment has been minimized.

Copy link

@StevenMapes StevenMapes commented Aug 7, 2020

Check the dependencies before and after each version is installed its likely that there is an underlying lib that's changed if it's not this package

@anshu7k

This comment has been minimized.

Copy link

@anshu7k anshu7k commented Aug 7, 2020

thanks bruno for the suggestion but i wrote on stackoverflow but didnot recieved any response there.

thanks for the advice steven, Let me chck the dependecies agian.. I will get back to u

@FrancisGauthier

This comment has been minimized.

Copy link

@FrancisGauthier FrancisGauthier commented Sep 9, 2020

Solution for QXcbConnection: Could not connect to display:
alias wkhtmltopdf='xvfb-run wkhtmltopdf'

Worked for my docker image. Thank you

@EvgeniySu

This comment has been minimized.

Copy link

@EvgeniySu EvgeniySu commented Oct 5, 2020

Instead of all from above, use this sample. It is just another wrapper over this library containing support for 3 platforms. Do not forget to copy Rotativa to your project.
https://github.com/fpanaccia/Wkhtmltopdf.NetCore.Example

@Garrett-R

This comment has been minimized.

Copy link

@Garrett-R Garrett-R commented Oct 8, 2020

To get the latest wkhtmltopdf version (0.12.6 as of now):

sudo apt update
sudo apt install wget xfonts-75dpi
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb
sudo dpkg -i wkhtmltox_0.12.6-1.bionic_amd64.deb

(the URL is found here)

@madhavparikh99

This comment has been minimized.

Copy link

@madhavparikh99 madhavparikh99 commented Dec 4, 2020

apt-get command not found is getting what should I do Now

@brunogaspar

This comment has been minimized.

Copy link
Owner Author

@brunogaspar brunogaspar commented Dec 4, 2020

apt-get command not found

Without giving us any information about your setup like what distro you're on, is quite impossible to know. But try using yum instead of apt for example.

what should I do Now

You should use Google and search for your problem, takes just a second..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment