我想使用 xhtml2pdf 将阿拉伯字符导出为 pdf,因为我在 django 应用程序中使用它。
我知道他们做了更新,说他们修复了它,但它对我不起作用,我使用了自定义字体但仍然不起作用。
因此,请任何人知道正确的加密方式或与之相关的任何方式,帮助我。
发票.html:
{% load static %}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<head>
<title>{{title}}</title>
<style type="text/css">
@font-face {
font-family: Amiri, "Amiri Font";
src: url("{% static 'font/Amiri-Italic.ttf'%}");
}
body {
font-weight: 200;
font-size: 14px;
}
</style>
</head>
<body><pdf:language name="arabic"/>
<div class='wrapper'>
<div class='header'>
<p class='title'>Invoice # {{ invoice_ID }} </p>
</div>
<div>
<div class='details'>
<pdf:language name="arabic"/>
<p> تجربة</p>
customername : {{customer_name}} <br><hr>
<hr class='hrItem' />
</div>
</div>
</body>
</html>
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
views.py :
from django.shortcuts import render, redirect, HttpResponse
import pandas as pd
from .models import SaleInvoice, TransferWays, User, InstallingCities
from siteManagment.models import MarketersManagment, WareHouses
from .utils import render_to_pdf
from django.core.validators import ValidationError
慕标琳琳