Hello, sorry, I'm working Django and I needed to render HTML pages to pdf, I tried xhtml2pdf but I did not like it, I could not use CSS properly. Now I am using pdfkit with wkhtmltopdf and I liked it but I have the problem that does not show me the images. (in Ubuntu linux). In summary, my code is as follows.
VIEWS
@login_required
def mypdfview (request):
template = get_template ('mipagina.html')
ctx = {'bla': bla}
html = template.render (ctx)
options = {
'page-size': 'Letter',
}
pdf = pdfkit.from_string (html, False, options = options,)
return HttpResponse (pdf, content_type = "application / pdf")
URLS
urlpatterns = [
url .....
]
if settings.DEBUG:
urlpatterns + = staticfiles_urlpatterns ()
urlpatterns + = static (settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
TEMPLATE
<img src = "{% static '../../media/imagen.png'%}" alt = ""> Hi
<img src = "/ media / imagen.jpg" alt = "">
I have been trying for two days to find a solution, the pdf is shown correctly but the image is not shown