Skip to content

Instantly share code, notes, and snippets.

@slickplaid
Last active September 11, 2022 12:51
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save slickplaid/5557321 to your computer and use it in GitHub Desktop.
Save slickplaid/5557321 to your computer and use it in GitHub Desktop.
How to install version 0.12.0 (latest as of 5/10/13) of wkhtmltopdf on Ubuntu 12.04 LTS headless server.
How to install version 0.12.0 (latest as of 5/10/13) of
wkhtmltopdf on Ubuntu 12.04 LTS headless server.
You'll need to have the user in the sudoers group or
modify the script to properly execute the root commands
needed.
There might be a little bit of overkill on the font
inclusions, but I ran into a lot of issues with specific
fonts missing and this seems to fix it.
Reply to this gist if you have questions. If you know
how to build it as a static binary reliably, let me
know. Due to the build time and the number of attempts
I've made at it unsuccessfully, I haven't been able to
get a reproducible 0.12.0 build working yet. The build
time should take about 1/2 to a full hour, so be
prepared for it. A static build can take upwards of 3+
hours.
sudo apt-get update && sudo apt-get upgrade -y;
sudo apt-get build-dep -y libqt4-gui libqt4-network libqt4-webkit;
sudo apt-get install -y openssl build-essential xorg git git-core libssl-dev libxrender-dev t1-xfree86-nonfree xfonts-scalable ttf-ubuntu-font-family ttf-mscorefonts-installer poppler-utils libqt4-dev qt4-dev-tools;
cd ~;
git clone git://gitorious.org/~antialize/qt/antializes-qt.git wkhtmltopdf-qt;
git clone git://github.com/antialize/wkhtmltopdf.git wkhtmltopdf;
cd wkhtmltopdf;
qmake-qt4;
cd ../wkhtmltopdf-qt;
git checkout 4.8.4;
QTDIR=. ./bin/syncqt;
./configure -nomake tools,examples,demos,docs,translations -opensource -prefix ../wkqt;
make -j3 && make install;
cd ../wkhtmltopdf;
../wkqt/bin/qmake;
make -j3 && sudo make install;
@slickplaid
Copy link
Author

If you get squares in place of actual characters, it is probably because you didn't build-dep the libqt4-gui, libqt4-network, and libqt4-webkit libraries. Without those, it won't render the fonts properly, even if you have the fonts installed on your system.

@slickplaid
Copy link
Author

UPDATE: If this happens, double check you ran the sudo apt-get build-dep -y libqt4-gui libqt4-network libqt4-webkit; command. I ran it before and kept getting this error, but after I ran it again, it installed more packages and seemed to fix the issue.

When you run the ./configure command on the custom QT build, if you get a configuration like this:

Architecture:  x86_64
Platform notes:

            - Also available for Linux: linux-kcc linux-icc linux-cxx

Build ..................  libs
Configuration ..........  release shared dll largefile stl precompile_header mmx 3dnow sse sse2 sse3 ssse3 sse4_1 sse4_2 avx  minimal-config small-config medium-config large-config full-config qt3support accessibility opengl reduce_exports ipv6 clock-gettime clock-monotonic mremap getaddrinfo ipv6ifname getifaddrs inotify png freetype system-zlib nis iconv openssl xshape xsync xrender mitshm xkb concurrent xmlpatterns multimedia audio-backend svg script scripttools declarative release
Debug .................. no
Qt 3 compatibility ..... yes
QtDBus module .......... no
QtConcurrent code ...... yes
QtGui module ........... yes
QtScript module ........ yes
QtScriptTools module ... yes
QtXmlPatterns module ... yes
Phonon module .......... no
Multimedia module ...... auto
SVG module ............. yes
WebKit module .......... yes
JavaScriptCore JIT ..... To be decided by JavaScriptCore
Declarative module ..... yes
Declarative debugging ...yes
Support for S60 ........ no
Symbian DEF files ...... no
STL support ............ yes
PCH support ............ yes
MMX/3DNOW/SSE/SSE2/SSE3. yes/yes/yes/yes/yes
SSSE3/SSE4.1/SSE4.2..... yes/yes/yes
AVX..................... yes
Graphics System ........ default
IPv6 support ........... yes
IPv6 ifname support .... yes
getaddrinfo support .... yes
getifaddrs support ..... yes
Accessibility .......... yes
NIS support ............ yes
CUPS support ........... no
Iconv support .......... yes
Glib support ........... no
GStreamer support ...... no
PulseAudio support ..... no
Large File support ..... yes
GIF support ............ plugin
TIFF support ........... plugin (qt)
JPEG support ........... plugin (qt)
PNG support ............ yes (qt)
MNG support ............ plugin (qt)
zlib support ........... system
Session management ..... no
OpenGL support ......... yes (Desktop OpenGL)
OpenVG support ......... no
NAS sound support ...... no
XShape support ......... yes
XVideo support ......... no
XSync support .......... yes
Xinerama support ....... no
Xcursor support ........ no
Xfixes support ......... no
Xrandr support ......... no
Xrender support ........ yes
Xi support ............. no
MIT-SHM support ........ yes
FontConfig support ..... no
XKB Support ............ yes
immodule support ....... yes
GTK theme support ...... no
SQLite support ......... plugin (qt)
OpenSSL support ........ yes (run-time)
Alsa support ........... no
ICD support ............ no
libICU support ......... no
Use system proxies ..... no

There will be a good chance something is wrong. You want it to look more like this:


Build ..................  libs
Configuration ..........  release shared dll largefile stl precompile_header mmx 3dnow sse sse2 sse3 ssse3 sse4_1 sse4_2 avx  minimal-config small-config me
dium-config large-config full-config qt3support phonon phonon-backend accessibility opengl reduce_exports ipv6 clock-gettime clock-monotonic mremap getaddri
nfo ipv6ifname getifaddrs inotify system-jpeg system-mng system-png png system-tiff system-freetype system-zlib nis cups iconv glib gstreamer dbus openssl x
11sm xshape xvideo xsync xrender mitshm fontconfig xkb alsa icu concurrent xmlpatterns multimedia audio-backend svg script scripttools declarative release
Debug .................. no
Qt 3 compatibility ..... yes
QtDBus module .......... yes (run-time)
QtConcurrent code ...... yes
QtGui module ........... yes
QtScript module ........ yes
QtScriptTools module ... yes
QtXmlPatterns module ... yes
Phonon module .......... yes
Multimedia module ...... auto
SVG module ............. yes
WebKit module .......... yes
JavaScriptCore JIT ..... To be decided by JavaScriptCore
Declarative module ..... yes
Declarative debugging ...yes
Support for S60 ........ no
Symbian DEF files ...... no
STL support ............ yes
PCH support ............ yes
MMX/3DNOW/SSE/SSE2/SSE3. yes/yes/yes/yes/yes
SSSE3/SSE4.1/SSE4.2..... yes/yes/yes
AVX..................... yes
Graphics System ........ default
IPv6 support ........... yes
IPv6 ifname support .... yes
getaddrinfo support .... yes
getifaddrs support ..... yes
Accessibility .......... yes
NIS support ............ yes
CUPS support ........... yes
Iconv support .......... yes
Glib support ........... yes
GStreamer support ...... yes
PulseAudio support ..... no
Large File support ..... yes
GIF support ............ plugin
TIFF support ........... plugin (system)
JPEG support ........... plugin (system)
PNG support ............ yes (system)
MNG support ............ plugin (system)
zlib support ........... system
Session management ..... yes
OpenGL support ......... yes (Desktop OpenGL)
OpenVG support ......... no
NAS sound support ...... no
XShape support ......... yes
XVideo support ......... yes
XSync support .......... yes
Xinerama support ....... runtime
Xcursor support ........ runtime
Xfixes support ......... runtime
Xrandr support ......... runtime
Xrender support ........ yes
Xi support ............. runtime
MIT-SHM support ........ yes
FontConfig support ..... yes
XKB Support ............ yes
immodule support ....... yes
GTK theme support ...... yes
MySQL support .......... plugin
PostgreSQL support ..... plugin
ODBC support ........... plugin
TDS support ............ plugin
SQLite support ......... plugin (qt)
OpenSSL support ........ yes (run-time)
Alsa support ........... yes
ICD support ............ no
libICU support ......... yes
Use system proxies ..... no

The FontConfig support ..... yes is probably one of the most important parts. I'm still research why this fails occasionally. Sometimes I can run it a second time and it works beautifully. Be aware of this when configuring.

If you need to reconfigure, run make confclean in the wkhtmltopdf-qt directory to clean out the old configuration options and start fresh.

@slickplaid
Copy link
Author

sudo apt-get update && sudo apt-get upgrade -y; sudo apt-get build-dep -y libqt4-gui libqt4-network libqt4-webkit; sudo apt-get install -y openssl build-essential xorg libssl-dev libxrender-dev t1-xfree86-nonfree xfonts-scalable ttf-ubuntu-font-family ttf-mscorefonts-installer poppler-utils libqt4-dev qt4-dev-tools;
cd ~; git clone git://gitorious.org/~antialize/qt/antializes-qt.git wkhtmltopdf-qt & git clone git://github.com/antialize/wkhtmltopdf.git wkhtmltopdf;
cd wkhtmltopdf; qmake-qt4; cd ../wkhtmltopdf-qt; git checkout 4.8.4; QTDIR=. ./bin/syncqt; ./configure -nomake tools,examples,demos,docs,translations -opensource -prefix ../wkqt;
nice -n 19 make -j1 && make install;
cd ../wkhtmltopdf; ../wkqt/bin/qmake; nice -n 19 make -j1 && sudo make install;

@asmt3
Copy link

asmt3 commented May 2, 2014

the make fails for me on 12.04. I get:

/usr/bin/ld: ../../build/qrc_wkhtmltopdf.o: relocation R_X86_64_32 against .rodata' can not be used when making a shared object; recompile with -fPIC ../../build/qrc_wkhtmltopdf.o: could not read symbols: Bad value collect2: ld returned 1 exit status make[1]: *** [../../bin/libwkhtmltox.so.0.12.1] Error 1 make[1]: Leaving directory/home/ubuntu/wkhtmltopdf/src/lib'
make: *** [sub-src-lib-make_default-ordered] Error 2

Any idea what I'm doing wrong? I'm not sure where I'm supposed to put this flag "-fPIC"...

@jmcclelland
Copy link

I get the same error.

@lisandi
Copy link

lisandi commented Aug 14, 2015

http://wkhtmltopdf.org/downloads.html
Why don't you simply install the new .deb package?

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