0
votes

I am using pdfkit to convert html into pdf. Everything seems to be working perfectly in development, but after building a docker image and running it locally, the pdf is generated but images are not loaded.

Here is my how I am rendering image, which seems to be working fine locally:

<img src="{{ host_url }}/static/tcs.jpg" style="width:100px;display:block;" />

Here's my code in django view function:

template = get_template("tcs_invoice.html")
data = {
  "host_url": settings.HOST
}
html = template.render(data)  # Renders the template with the context data.
pdf = pdfkit.from_string(html, False)
 return HttpResponse(pdf, content_type='application/pdf')

I have installed wkhtmltopdf on my docker container. When I hit the url in the browser the image is shown. why does it not render in production mode.

1

1 Answers

0
votes

I had the same issue this answer did the trick: wkhtmltopdf, 0.12.6, Warning: Blocked access to file

It ended up being a change of behavior after wkhtmltopdf 0.12.6 where local file access is disabled by default, so you need to wether specify the files you want to allow using the --allow <file> option or set --enable-local-file-access to allow any files.