Skip to content

Instantly share code, notes, and snippets.

@cornernote
Last active April 30, 2021 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cornernote/09221c5896d36133c3f36ecc13c928aa to your computer and use it in GitHub Desktop.
Save cornernote/09221c5896d36133c3f36ecc13c928aa to your computer and use it in GitHub Desktop.
docker test for wkhtmltopdf

Play with Docker - WKHTMLTOPDF

There are many way to try out WKHTMLTOPDF, a really slick one is creating a stack on Play with Docker.

Login or signup, then create a new instance.

Download a Docker application definition:

curl -Lo docker-compose.yml https://gist.githubusercontent.com/cornernote/09221c5896d36133c3f36ecc13c928aa/raw/ca4c8504445fbc2c214250a49ffef506c08bd8c9/docker-compose.yml
curl -Lo Dockerfile https://gist.githubusercontent.com/cornernote/09221c5896d36133c3f36ecc13c928aa/raw/ca4c8504445fbc2c214250a49ffef506c08bd8c9/Dockerfile

Optionally build the stack

docker-compose build

Now try to generate PDFs

docker-compose run --rm wkhtmltopdf wkhtmltopdf google.com /app/test.pdf
docker-compose run --rm wkhtmltopdf wkhtmltopdf example.com /app/test.pdf
version: '2'
services:
wkhtmltopdf:
build:
dockerfile: Dockerfile
context: .
volumes:
- ./:/app
FROM debian:stretch
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get -y install \
curl && \
## Install wkhtmltopdf
curl -L https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.stretch_amd64.deb \
-o wkhtmltox_0.12.6-1.stretch_amd64.deb && \
apt-get -y install \
wkhtmltopdf \
build-essential \
openssl \
libssl1.0-dev \
xorg \
xvfb && \
dpkg -i wkhtmltox_0.12.6-1.stretch_amd64.deb && \
rm -f wkhtmltox_0.12.6-1.stretch_amd64.deb && \
# Install mscorefonts
curl -L http://ftp.us.debian.org/debian/pool/contrib/m/msttcorefonts/ttf-mscorefonts-installer_3.6_all.deb \
-o ttf-mscorefonts-installer_3.6_all.deb && \
apt-get -y install \
wget \
cabextract && \
dpkg -i ttf-mscorefonts-installer_3.6_all.deb && \
rm -f ttf-mscorefonts-installer_3.6_all.deb && \
# Cleanup
apt-get -y autoremove && \
apt-get clean
@niloct
Copy link

niloct commented Apr 28, 2021

This is broken today. Could you fix this gist ?

@cornernote
Copy link
Author

@niloct - seems a few things changed. I have updated the build for the current version 0.12.6

@niloct
Copy link

niloct commented Apr 30, 2021

Thanks man.

On Mac OS Catalina there is a warning which will become a error in the future:

[WARNING]: Empty continuation line found in:
    RUN apt-get update &&     apt-get -y install         curl &&     curl -L https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.stretch_amd64.deb         -o wkhtmltox_0.12.6-1.stretch_amd64.deb &&     apt-get -y install             wkhtmltopdf             build-essential             openssl             libssl1.0-dev             wget             xorg             xvfb &&     dpkg -i wkhtmltox_0.12.6-1.stretch_amd64.deb &&     rm -f wkhtmltox_0.12.6-1.stretch_amd64.deb &&     curl -L http://ftp.us.debian.org/debian/pool/contrib/m/msttcorefonts/ttf-mscorefonts-installer_3.6_all.deb         -o ttf-mscorefonts-installer_3.6_all.deb &&     apt-get -y install             cabextract &&     dpkg -i ttf-mscorefonts-installer_3.6_all.deb &&     rm -f ttf-mscorefonts-installer_3.6_all.deb &&     apt-get -y autoremove &&     apt-get clean
[WARNING]: Empty continuation lines will become errors in a future release.

And the building is so slow...

I gathered information about a sleeker build for wkhtmltopdf here: https://stackoverflow.com/a/67304151/152016

What do you think of it ?

Thanks again.

@cornernote
Copy link
Author

cornernote commented Apr 30, 2021 via email

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