Невозможно закодировать кириллические символы xhmt2pdf в django
# libraries
from io import BytesIO
from django.http import HttpResponse
from django.template.loader import get_template
from xhtml2pdf import pisa
from django.utils.encoding import smart_str
# defining the function to convert an HTML file to a PDF file
def html_to_pdf(template_src, context_dict={}):
template = get_template(template_src)
html = template.render(context_dict)
result = BytesIO()
pdf = pisa.pisaDocument(BytesIO(html.encode("ISO-8859-1")), result)
if not pdf.err:
return HttpResponse(result.getvalue(), content_type='application/pdf')
return None
В HTML у меня есть несколько русских слов. Когда я попытался закодировать эти символы, в моем pdf появилась куча непонятных символов. Я пробовал менять формат кодировки на "UTF-8", "UTF-16", но это не помогло.