I was working with my django app on my localserver and There was a view that shows me pdf using wkhtmltopdf, when I decided to dockerize my app this result is shown to me when I try to reach the pdf:
In views.py:
wkhtml_to_pdf = os.path.join(
settings.BASE_DIR, "wkhtmltopdf.exe")
def resume_pdf(request,id):
# return render(request, 'frontend/index.html')
options = {
'page-size': 'A4',
'page-height': "13in",
'page-width': "10in",
'margin-top': '0in',
'margin-right': '0in',
'margin-bottom': '0in',
'margin-left': '0in',
'encoding': "UTF-8",
'no-outline': None
}
template_path = 'frontend/thepdf.html'
template = get_template(template_path)
context = {"name": "Areeba Seher"}
html = template.render(context)
config = pdfkit.configuration(wkhtmltopdf=wkhtml_to_pdf)
pdf = pdfkit.from_string(html, False, configuration=config, options=options)
# Generate download
response = HttpResponse(pdf, content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="resume.pdf"'
theEntry = entry.objects.get(id= id)
context = {'entry' : theEntry, 'entrybody': markdown(theEntry.body) }
# print(response.status_code)
if response.status_code != 200:
return HttpResponse('We had some errors <pre>' + html + '</pre>')
# return response
return PDFTemplateResponse(request=request, cmd_options={'disable-javascript':True}, template=template, context=context)
my Dockerfile:
FROM python:3.10.5
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
RUN apt-get update \
&& apt-get -y install tesseract-ocr
RUN pip install --upgrade pip
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
So how can I make wkhtmltopdf work on dockerized django app?