10k20
10k20

Reputation: 177

How to use wkHTMLtoPDF running in docker-compose in Django application

I have a problem with undestanding on how to use wkHTMltoPDF, that I run in docker-compose and Django. Also I can't understand how to setup it in Django and use it in the right way. I will be very glad for any help. My docker-compose.yml:

version: '3.7'

services:
  db:
    image: postgres:13.0
    restart: always
    environment:
      POSTGRES_PASSWORD: trytofindme
    ports:
      - 15432:5432
  adminer:
    image: adminer
    restart: always
    ports:
      - 8020:8080
  wkhtmltopdf:
    image: openlabs/docker-wkhtmltopdf-aas:latest
    volumes:
      - .:/data

So, I can't even imagine where I should do it in Django. The example of usage that I need: on main page I fill some forms and then click button "Generate". It should send async requests on generating pdf file of this page with filled forms. Can anybody help me to realise it?

Upvotes: 0

Views: 1908

Answers (1)

Shantanu
Shantanu

Reputation: 692

You need to setup a new image, you can take use python 3.7 as base image. The wkhtmltopdf binaries can be made using https://github.com/aantonw/docker-alpine-wkhtmltopdf-patched-qt.

This is how my docker file looked.

FROM python:3.7-alpine

COPY ./requirements.txt .

RUN set -e; \
        apk add --no-cache mariadb-connector-c-dev ;\
        apk add --no-cache --virtual .build-deps \
        gcc \
        libc-dev \
        linux-headers \
        mariadb-dev \
        jpeg-dev \
        zlib-dev \
        libffi-dev \
        musl-dev \
        libxml2-dev \
        libxslt-dev \
        wkhtmltopdf \
        poppler-utils;
COPY docker_files/wkhtmltopdf /usr/bin/wkhtmltopdf
COPY docker_files/wkhtmltoimage /usr/bin/wkhtmltoimage
RUN set -e; \
    pip install --upgrade pip; \
    pip install -r requirements.txt;
COPY ./src /app
WORKDIR /app
CMD [ "python", "manage.py", "runserver" ]

Upvotes: 0

Related Questions