iam trying to create a report using django but the arabic word coes out redacted for some reason this is the and example of the pdf
this is my view function
this function and templates works just fine with downloading the pdf but when it comes out to rendering arabic it does’t work
i have downloaded this arabic font NotoKufiArabic-VariableFont_wght.ttf but it won’t work for some reason
<code>from django.http import HttpResponse
from django.template.loader import get_template
from xhtml2pdf import pisa
from io import BytesIO
from django.shortcuts import get_object_or_404
from ..models import Supplier, TransactionModel
from django.db.models import Sum
def generate_pdf_report(request, supplier_name):
supplier = get_object_or_404(Supplier, supplier_name=supplier_name)
transactions = TransactionModel.objects.filter(supplier_name=supplier).order_by('payment_date')
total_paid = transactions.aggregate(Sum('payment_amount'))['payment_amount__sum'] or 0
remaining_amount = supplier.total_amount - total_paid
context = {
'supplier': supplier,
'transactions': transactions,
'total_paid': total_paid,
'remaining_amount': remaining_amount,
}
template = get_template('supplier_report.html')
html = template.render(context)
result = BytesIO()
pdf = pisa.pisaDocument(BytesIO(html.encode("UTF-8")), result, encoding='UTF-8')
if not pdf.err:
response = HttpResponse(result.getvalue(), content_type='application/pdf')
response['Content-Disposition'] = f'attachment; filename="{supplier_name}_report.pdf"'
return response
return HttpResponse('Error generating PDF', status=400)
</code>
<code>from django.http import HttpResponse
from django.template.loader import get_template
from xhtml2pdf import pisa
from io import BytesIO
from django.shortcuts import get_object_or_404
from ..models import Supplier, TransactionModel
from django.db.models import Sum
def generate_pdf_report(request, supplier_name):
supplier = get_object_or_404(Supplier, supplier_name=supplier_name)
transactions = TransactionModel.objects.filter(supplier_name=supplier).order_by('payment_date')
total_paid = transactions.aggregate(Sum('payment_amount'))['payment_amount__sum'] or 0
remaining_amount = supplier.total_amount - total_paid
context = {
'supplier': supplier,
'transactions': transactions,
'total_paid': total_paid,
'remaining_amount': remaining_amount,
}
template = get_template('supplier_report.html')
html = template.render(context)
result = BytesIO()
pdf = pisa.pisaDocument(BytesIO(html.encode("UTF-8")), result, encoding='UTF-8')
if not pdf.err:
response = HttpResponse(result.getvalue(), content_type='application/pdf')
response['Content-Disposition'] = f'attachment; filename="{supplier_name}_report.pdf"'
return response
return HttpResponse('Error generating PDF', status=400)
</code>
from django.http import HttpResponse
from django.template.loader import get_template
from xhtml2pdf import pisa
from io import BytesIO
from django.shortcuts import get_object_or_404
from ..models import Supplier, TransactionModel
from django.db.models import Sum
def generate_pdf_report(request, supplier_name):
supplier = get_object_or_404(Supplier, supplier_name=supplier_name)
transactions = TransactionModel.objects.filter(supplier_name=supplier).order_by('payment_date')
total_paid = transactions.aggregate(Sum('payment_amount'))['payment_amount__sum'] or 0
remaining_amount = supplier.total_amount - total_paid
context = {
'supplier': supplier,
'transactions': transactions,
'total_paid': total_paid,
'remaining_amount': remaining_amount,
}
template = get_template('supplier_report.html')
html = template.render(context)
result = BytesIO()
pdf = pisa.pisaDocument(BytesIO(html.encode("UTF-8")), result, encoding='UTF-8')
if not pdf.err:
response = HttpResponse(result.getvalue(), content_type='application/pdf')
response['Content-Disposition'] = f'attachment; filename="{supplier_name}_report.pdf"'
return response
return HttpResponse('Error generating PDF', status=400)
and this is my template
<code><html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<title>تقرير المورد - {{ supplier.supplier_name }}</title>
<style>
@font-face {
font-family: 'Arabic Font';
src: url('../../NotoKufiArabic-VariableFont_wght.ttf') format('truetype');
}
body {
font-family: 'ArialArabic', Arial, sans-serif;
direction: rtl;
text-align: right;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: right;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<h1>تقرير المورد - {{ supplier.supplier_name }}</h1>
<p>نوع المورد: {{ supplier.get_supplier_type_display }}</p>
<p>طريقة الدفع: {{ supplier.get_payment_method_display }}</p>
<p>المبلغ الكلي: {{ supplier.total_amount }}</p>
<p>المبلغ المدفوع: {{ total_paid }}</p>
<p>المبلغ المتبقي: {{ remaining_amount }}</p>
<p>تاريخ الدفعة القادمة: {{ supplier.next_payment_date }}</p>
<p>اسم المصدر: {{ supplier.issuer_name }}</p>
<p>البريد الإلكتروني: {{ supplier.email }}</p>
<h2>جدول المعاملات</h2>
<table>
<thead>
<tr>
<th>رقم الدفعة</th>
<th>تاريخ الدفع</th>
<th>قيمة الدفعة</th>
</tr>
</thead>
<tbody>
{% for transaction in transactions %}
<tr>
<td>{{ transaction.payment_num }}</td>
<td>{{ transaction.payment_date }}</td>
<td>{{ transaction.payment_amount }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>```
</code>
<code><html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<title>تقرير المورد - {{ supplier.supplier_name }}</title>
<style>
@font-face {
font-family: 'Arabic Font';
src: url('../../NotoKufiArabic-VariableFont_wght.ttf') format('truetype');
}
body {
font-family: 'ArialArabic', Arial, sans-serif;
direction: rtl;
text-align: right;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: right;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<h1>تقرير المورد - {{ supplier.supplier_name }}</h1>
<p>نوع المورد: {{ supplier.get_supplier_type_display }}</p>
<p>طريقة الدفع: {{ supplier.get_payment_method_display }}</p>
<p>المبلغ الكلي: {{ supplier.total_amount }}</p>
<p>المبلغ المدفوع: {{ total_paid }}</p>
<p>المبلغ المتبقي: {{ remaining_amount }}</p>
<p>تاريخ الدفعة القادمة: {{ supplier.next_payment_date }}</p>
<p>اسم المصدر: {{ supplier.issuer_name }}</p>
<p>البريد الإلكتروني: {{ supplier.email }}</p>
<h2>جدول المعاملات</h2>
<table>
<thead>
<tr>
<th>رقم الدفعة</th>
<th>تاريخ الدفع</th>
<th>قيمة الدفعة</th>
</tr>
</thead>
<tbody>
{% for transaction in transactions %}
<tr>
<td>{{ transaction.payment_num }}</td>
<td>{{ transaction.payment_date }}</td>
<td>{{ transaction.payment_amount }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>```
</code>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<title>تقرير المورد - {{ supplier.supplier_name }}</title>
<style>
@font-face {
font-family: 'Arabic Font';
src: url('../../NotoKufiArabic-VariableFont_wght.ttf') format('truetype');
}
body {
font-family: 'ArialArabic', Arial, sans-serif;
direction: rtl;
text-align: right;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: right;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<h1>تقرير المورد - {{ supplier.supplier_name }}</h1>
<p>نوع المورد: {{ supplier.get_supplier_type_display }}</p>
<p>طريقة الدفع: {{ supplier.get_payment_method_display }}</p>
<p>المبلغ الكلي: {{ supplier.total_amount }}</p>
<p>المبلغ المدفوع: {{ total_paid }}</p>
<p>المبلغ المتبقي: {{ remaining_amount }}</p>
<p>تاريخ الدفعة القادمة: {{ supplier.next_payment_date }}</p>
<p>اسم المصدر: {{ supplier.issuer_name }}</p>
<p>البريد الإلكتروني: {{ supplier.email }}</p>
<h2>جدول المعاملات</h2>
<table>
<thead>
<tr>
<th>رقم الدفعة</th>
<th>تاريخ الدفع</th>
<th>قيمة الدفعة</th>
</tr>
</thead>
<tbody>
{% for transaction in transactions %}
<tr>
<td>{{ transaction.payment_num }}</td>
<td>{{ transaction.payment_date }}</td>
<td>{{ transaction.payment_amount }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>```