TTFError at / Не удается открыть файл "C:\Users\-\AppData\Local\Temp\tmp52b4p0wi.ttf"
Я пытаюсь вывести арабский контент в pdf, через библиотеку xhtml2pdf в Django. но, как указано в документации, xhtml2pdf имеет ограниченное количество поддерживаемых языков, поэтому я использую ручной файл .ttf, но он показывает мне эту ошибку
Вот мой views.py
def generate_pdf(request):
pdf = render_to_pdf('index.html')
if pdf:
response = HttpResponse(pdf, content_type='application/pdf')
filename = "Invoice_.pdf"
content = "inline; filename='%s'" % filename
download = request.POST.get("download")
if download:
content = "attachment; filename='%s'" % filename
response['Content-Disposition'] = content
receipt_file = BytesIO(pdf.content)
return response
utils.py
from io import BytesIO
from django.http import HttpResponse
from django.template.loader import get_template
from xhtml2pdf import pisa
def render_to_pdf(template_src, context_dict={}):
template = get_template(template_src)
html = template.render(context_dict)
result = BytesIO()
pdf = pisa.pisaDocument(BytesIO(html.encode("utf-8")), result)
if not pdf.err:
return HttpResponse(result.getvalue(), content_type='application/pdf')
return None
Затем главное - мой .html файл, с .ttf форматом шрифта
.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Gift PDF</title>
<style type="text/css">
@font-face {
font-family: ArialUnicode;
src: url("D:\Software House\Extras\Tests\pdfTest\main_project\static\fonts\arial-unicode-ms.ttf");
}
body {
margin: 0;
font-family: "ArialUnicode", sans-serif;
}
</style>
</head>
<body>
<div class="headings">إلي</div>
</body>
</html>