Answer the question
In order to leave comments, you need to log in
Why doesn't it recognize Cyrillic when converting HTMl to PDF (Django 3.2)?
When converting HTML to PDF, I encountered a problem with Cyrillic recognition. Django 3.2 website (Python 3.7)
I use xhtml2pdf for generation.
The user fills out a form on the site, and after that, it must be printed. The file is uploaded, but instead of Russian text there are squares ■■■■■■■ ■■■■■■
def pdf_create(request):
ty = Technical_Y.objects.all()
template_path = 'my.html'
context = {'ty': ty}
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="my.pdf"'
template = get_template(template_path)
html = template.render(context)
pisa_status = pisa.CreatePDF(html, dest=response)
if pisa_status.err:
return HttpResponse(html)
return response
Answer the question
In order to leave comments, you need to log in
Because the font used to generate the pdf does not support Cyrillic characters.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question