Xhtml2pdf не показывает личный шрифт, я не понимаю, как я должен импортировать свой шрифт
Мне нужно создать pdf и мне нужен мой собственный шрифт, который присутствует в static / font / Я просто не понимаю, как его импортировать. шрифт всегда остается тем же самым, и я не знаю, как это сделать, может кто-нибудь помочь мне?
Я использовал:
- http://127.0.0.1:8000/static/font/titolo.ttf
- /static/font/titolo.ttf
- {% static 'font/titolo.ttf' %}
но не работает, как мне импортировать мой шрифт, чтобы он работал правильно?
css
<style>
@font-face {
font-family: "Titolo";
src: url('/static/font/titolo.ttf');
}
@page {
size: A4 portrait;
@frame header_frame{
-pdf-frame-content: header;
top: 10mm; width: 210mm; margin: 0 10mm;
}
@frame content_frame{
width: 210mm; top: 40mm; margin: 0 10mm;
}
@frame footer_frame{
-pdf-frame-content: footer;
top: 276mm; width: 220mm; margin: 0 10mm;
}
}
h1 {font-size: 4rem; margin-bottom: 0; font-family: 'Titolo';}
#header p, .total p {font-size: 1.4rem;}
.title-element {margin-bottom: 1.5rem}
.element img {width: 60px; height: 60px;}
.element p, .title-element p {font-size: 1.2rem;}
.element td {text-align: center;}
.title-element p {line-height: 1;}
</style>
просмотров
from django.http import HttpResponse
from django.template.loader import get_template
from xhtml2pdf import pisa
def pdf_order(request, id):
ordine = get_object_or_404(Summary, user = request.user, id = id)
# template e context
template_path = 'pdf.html'
context = {'ordine': ordine}
# oggetto django formato pdf
response = HttpResponse(content_type='application/pdf')
# view file
response['Content-Disposition'] = 'filename="ordine#' + ordine.code + '.pdf"'
# renderizzo il template
template = get_template(template_path)
html = template.render(context)
# cero il pdf
pisa_status = pisa.CreatePDF(
html,
dest = response
)
# errore
if pisa_status.err:
return HttpResponse('Errore nella creazione del pdf')
return response