У меня проблема с генерацией PDF с использованием Django. в моем шаблоне у меня есть персидские данные, подобные этому, احمدو محمود, но когда в файле pdf показано, что персидские данные были хэшированы следующим образом.
это мой взгляд
def render_to_pdf(template_src, context_dict={}):
template = get_template(template_src)
html = template.render(context_dict)
result = BytesIO()
print(html)
pdf = pisa.pisaDocument(BytesIO(html.encode("utf-8")), result )
if not pdf.err:
return HttpResponse(result.getvalue(),
content_type='application/pdf')
return None
эта функция называется шаблоном
def mypdf(request):
pdf = render_to_pdf('viewpdf.html')
return HttpResponse(pdf, content_type='application/pdf')
Это мой шаблон
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
`enter code here`<html>
<head>
<meta charset="utf-8">
<title>Title</title>
<style type="text/css">
body {
font-weight: 200;
font-size: 14px;
}
.header {
font-size: 20px;
font-weight: 100;
text-align: center;
color: #007cae;
}
.title {
font-size: 22px;
font-weight: 100;
/* text-align: right;*/
padding: 10px 20px 0px 20px;
}
.title span {
color: #007cae;
}
.details {
padding: 10px 20px 0px 20px;
text-align: left !important;
/*margin-left: 40%;*/
}
.hrItem {
border: none;
height: 1px;
/* Set the hr color */
color: #333; /* old IE */
background-color: #fff; /* Modern Browsers */
}
</style>
</head>
<body>
<div class='wrapper'>
<div class='header'>
<p class='title'>Invoice # </p>
</div>
<div>
<div class='details'>
<h1>احمدومحمود</h1>
<hr class='hrItem' />
</div>
</div>
</body>
</html>
в конце это вывод:
введите описание изображения здесь