wkhtmltopdf / packaging

Packaging of wkhtmltopdf releases
https://wkhtmltopdf.org/downloads.html#stable
305 stars 138 forks source link

Missing dependencies xfonts-75dpi xfonts-base #78

Closed rubnov closed 3 years ago

rubnov commented 3 years ago

Not sure if this is the appropriate repo to raise this issue. Would appreciate your guidance.

I am failing to install and use wkhtmltopdf in my docker container, running Debian buster. Host runs Ubuntu 16.04. The docker container is based on python 3.8.5, with pdfkit 0.6.1 installed via requirements file, and wkhtmltopdf installed in the Dockerfile via apt-get.

Dockerfile:

FROM python:3.8.5

RUN mkdir /assets

RUN apt-get update

ENV PYTHONUNBUFFERED 1
ENV CPPFLAGS -fPIC

RUN apt-get install -y --no-install-recommends apt-utils
RUN apt-get install -y wget build-essential libgeos-dev libev-dev libssl-dev wkhtmltopdf
RUN python -m ensurepip --upgrade
RUN pip install --upgrade pip
RUN pip install -U setuptools
...

This installs the dist build 0.12.5-1 buster amd64 and my docker container shows the following info:

$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

$uname -m
x86_64

$ which wkhtmltopdf
/usr/local/bin/wkhtmltopdf

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

So the dist package seems to fit my architecture, and pdfkit indeed generates a valid pdf from html when running the container in my localhost (Mac OS X). However, it fails in production (Ubuntu 16.04), producing a blank-page pdf.

SSH to the production host and testing this in a shell shows the error details:

$ docker-compose -f <docker-compose.yml> run <container> python manage.py shell_plus
>>> import pdfkit
>>> html = open('sample.html', mode="r", encoding="utf-8")
>>> htmlstring = html.read()
>>> html.close()
>>> pdfkit.from_string(htmlstring, 'out.pdf')

OSError: wkhtmltopdf exited with non-zero code 1. error:
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
QStandardPaths: wrong ownership on runtime directory /tmp/runtime-root, -2 instead of 0
Exit with code 1, due to unknown error.

Following this suggestion, I tried to download and install the official binary from the releases/downloads page. I've changed my Dockerfile to:

# wkhtmltopdf
RUN mkdir -p /wkhtmltox
WORKDIR /wkhtmltox
RUN wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.buster_amd64.deb
ARG DEBIAN_FRONTEND=noninteractive
RUN dpkg -i ./wkhtmltox_0.12.5-1.buster_amd64.deb
RUN rm -r /wkhtmltox/

The above fails with the error:

Selecting previously unselected package wkhtmltox.
(Reading database ... 24789 files and directories currently installed.)
Preparing to unpack .../wkhtmltox_0.12.5-1.buster_amd64.deb ...
Unpacking wkhtmltox (1:0.12.5-1.buster) ...
dpkg: dependency problems prevent configuration of wkhtmltox:
 wkhtmltox depends on xfonts-75dpi; however:
  Package xfonts-75dpi is not installed.
 wkhtmltox depends on xfonts-base; however:
  Package xfonts-base is not installed.

dpkg: error processing package wkhtmltox (--install):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 wkhtmltox

Why does this package have broken dependencies? Am I installing it incorrectly?

Trying to resolve this, I added:

RUN apt-get --assume-yes install xfonts-75dpi xfonts-base

to my Dockerfile before dpkg and was able to build the container. This even worked on my localhost, producing a valid pdf. However, it now fail again in production on Ubuntu 16.04 host with a different error:

$ docker-compose -f <docker-compose.yml> run <container> python manage.py shell_plus
>>> import pdfkit
>>> html = open('sample.html', mode="r", encoding="utf-8")
>>> htmlstring = html.read()
>>> html.close()
>>> pdfkit.from_string(htmlstring, 'out.pdf')

OSError: wkhtmltopdf reported an error:
QFont::setPixelSize: Pixel size <= 0 (0)
QFont::setPixelSize: Pixel size <= 0 (0)
QFont::setPixelSize: Pixel size <= 0 (0)
QFont::setPixelSize: Pixel size <= 0 (0)
QFont::setPixelSize: Pixel size <= 0 (0)
QFont::setPixelSize: Pixel size <= 0 (0)
QFont::setPixelSize: Pixel size <= 0 (0)
QFont::setPixelSize: Pixel size <= 0 (0)
Exit with code 1 due to network error: HostNotFoundError

This is also mentioned in issue 2532

Please help me understand how to get wkhtmltopdf working.

ashkulz commented 3 years ago

The HostNotFoundError is due to wkhtmltopdf/wkhtmltopdf#4536, and I see you've already found a fix.