How to install wkhtmltopdf on Docker php-fpm Alpine Linux?
Asked Answered
F

2

10

I installed Wkhtmltopdf on Alpine Docker with the following command:

apk add --no-cache wkhtmltopdf

However when I try to run wkhtmltopdf I get:

/usr/bin/wkhtmltopdf  "test.html" "test.pdf"
Cannot mix incompatible Qt library (version 0x50c03) with this library (version 0x50c00)
Aborted (core dumped)

How can I fix that?

EDIT:

Seems like the issue is that some other package installs not compatable qt version. Here's my Dockerfile:

RUN apk --no-cache update \
    && apk --no-cache upgrade \
    && apk add --no-cache \
            mysql-client \
            php7-mysqli \
            php7-pdo \
            freetype \
            libpng \
            freetype-dev \
            libpng-dev \
            jpeg-dev \
            libjpeg \
            libjpeg-turbo-dev \
            wget \
            zlib-dev \
            ttf-freefont \
            fontconfig \
            xvfb \
            libxrender-dev \
            gettext \
            gettext-dev \
            libxml2-dev \
            gnu-libiconv-dev \
            autoconf \
            g++ \
            git \
            bash \
            wkhtmltopdf
Fonz answered 3/6, 2019 at 11:4 Comment(4)
What version of Alpine are you using? I've just tested with 3.9.4 and it works.Bacchanalia
VERSION_ID=3.9.2 I use php:7.2-fpm-alpine as a base image. Not sure if it's possible to update to 3.9.4Fonz
Could you edit your question with this information (in particular the base image)? The problem comes from php base image I think, because it works on vanilla Alpine (alpine:3.9.2).Bacchanalia
I was told here (github.com/mileszs/wicked_pdf/issues/605#issuecomment-499601632) that this works: github.com/alloylab/Docker-Alpine-wkhtmltopdfHoo
A
12

You cannot install wkhtmltopdf from alpine repositories starting of 3.15 version https://pkgs.alpinelinux.org/packages?name=wkhtmltopdf&branch=edge&repo=&arch=&maintainer=

If you want to use wkhtmltopdf in the newer alpine (3.17 below). You can copy bin files from other images like https://github.com/Surnet/docker-wkhtmltopdf and install related libraries.

Here is Dockerfile:

FROM surnet/alpine-wkhtmltopdf:3.16.2-0.12.6-full as wkhtmltopdf
FROM php:8.2-fpm-alpine3.17 AS app

# wkhtmltopdf install dependencies
RUN apk add --no-cache \
        libstdc++ \
        libx11 \
        libxrender \
        libxext \
        libssl1.1 \
        ca-certificates \
        fontconfig \
        freetype \
        ttf-droid \
        ttf-freefont \
        ttf-liberation \
        # more fonts
        ;
# wkhtmltopdf copy bins from ext image
COPY --from=wkhtmltopdf /bin/wkhtmltopdf /bin/libwkhtmltox.so /bin/


# install php extensions, apache/nginx etc.

Allin answered 12/12, 2022 at 15:30 Comment(1)
alternatively, you can just use the small wkhtmltopdf package and need libxrender and fontconfig and whatever fonts, i.e., : FROM surnet/alpine-wkhtmltopdf:3.20.1-0.12.6-small as wkhtmltopdf .... RUN apk update && apk add --no-cache libxrender fontconfig # other fonts COPY --from=wkhtmltopdf /bin/wkhtmltopdf /bin/libwkhtmltox.so /bin/ ...Cheops
C
1

you can also just use the small wkhtmltopdf package and need libxrender and fontconfig and whatever fonts, i.e., :

FROM surnet/alpine-wkhtmltopdf:3.20.1-0.12.6-small as wkhtmltopdf 

... 

# install the libxrender, fontconfig and any other fonts you need
RUN apk update && apk add --no-cache libxrender fontconfig # other fonts 

# copy the binary file from the wkhtmltopdf small image to your image
COPY --from=wkhtmltopdf /bin/wkhtmltopdf /bin/wkhtmltopdf 

...

this makes the dockerfile a lot easier to read

Cheops answered 19/7 at 13:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.