Installing wkhtmltopdf on Python 3.6 Alpine

Viewed 2624

Has anyone been able to install wkhtmltopdf on python:3.6.0-alpine.

I have tried all the solutions present on the internet. I need to use pdfkit which internally uses wkhtmltopython to convert html to pdf.

2 Answers

You might need wkhtmltopdf and xvfb to run on a server:

apk add wkhtmltopdf xvfb

In case someone would like to have the full line that needs to be added to the Dockerfile:

RUN apk update && apk add wkhtmltopdf

or:

RUN apt-get update && apt-get install -y wkhtmltopdf

You can then use the following code in your "Dockerized" Python script:

import pdfkit
path_wkhtmltopdf = '/usr/bin/wkhtmltopdf'
config = pdfkit.configuration(wkhtmltopdf=path_wkhtmltopdf)
pdfkit.from_string(html, '<direction/of/the/report.pdf>', configuration=config)
Related