Skip to content

Instantly share code, notes, and snippets.

@brunogaspar
Last active October 7, 2022 09:08
Show Gist options
  • Save brunogaspar/bd89079245923c04be6b0f92af431c10 to your computer and use it in GitHub Desktop.
Save brunogaspar/bd89079245923c04be6b0f92af431c10 to your computer and use it in GitHub Desktop.
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

@ihr-it-projekt
Copy link

@yusufyilmaz I have the same problem

QXcbConnection: Could not connect to display

Do you have a solution?

@vankov1
Copy link

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
Copy link

kai101 commented Jan 25, 2018

I have made a small deployment instruction here

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

@H1D1
Copy link

H1D1 commented Mar 6, 2018

retourner QXcbConnection: Could not connect to display

@saberanaibi
Copy link

you have to be connected to the internet

@nitinnath
Copy link

nice brother

@festusngor
Copy link

festusngor commented Apr 19, 2018

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

@deivid11
Copy link

deivid11 commented Sep 6, 2018

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

@kunicmarko20
Copy link

Thank you @deivid11

@damuz91
Copy link

damuz91 commented Oct 4, 2018

@Pedro75
Copy link

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
Copy link

@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
Copy link

Thanks, @brunogaspar it works!

@pvin
Copy link

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
Copy link
Author

@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
Copy link

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

Thanks!!! This work for me!

@shamshi1988
Copy link

@brunogaspar Thanks. It work's for me

@0xm4ud
Copy link

0xm4ud commented Dec 17, 2019

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

true story, blees u, mate !

@StevenMapes
Copy link

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

@anshu7k
Copy link

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
Copy link
Author

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
Copy link

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
Copy link
Author

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
Copy link

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
Copy link

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
Copy link

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

Worked for my docker image. Thank you

@EvgeniySu
Copy link

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
Copy link

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)

@aipladmin
Copy link

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

@brunogaspar
Copy link
Author

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