Как конвертировать html в pdf в django, кириллический шрифт

Я пытаюсь конвертировать html в pdf в django с помощью xhtml2pdf, и успешно конвертировал html в pdf в английский алфавит и цифры, но в русский алфавит (кириллица) он выдает мне черное квадратное поле, Введите описание изображения здесь

Вот что я пробовал:

views.py

def download(request):
    user = request.user
    template_path = 'faktura.html'
    context = {'user': user}
    response = HttpResponse(content_type='application/pdf')
    response['Content-Disposition'] = 'attachment; filename="contract.pdf"'
    template = get_template(template_path)
    html = template.render(context)

    # create a pdf
    pisa_status = pisa.CreatePDF(
        html, dest=response)
    # if error then show some funy view
    if pisa_status.err:
        return HttpResponse('We had some errors <pre>' + html + '</pre>')
    return response

И html-файл:

Как я могу исправить эту ошибку, пожалуйста, помогите мне!?

добавьте в свой html (Alice-Regular.ttf) - русский шрифт

 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />



    <style>
        @font-face {
        font-family: "Alice-Regular";
        src: url("/fonts/Alice-Regular.ttf") format("truetype");
        }

        body {
        font-family: "Alice-Regular";
        font-size: 20px
        }
    </style>

и вы можете прочитать :https://github.com/xhtml2pdf/xhtml2pdf/issues/129

Вернуться на верх