Django 改变 pdf 字体的 xhtml2pdf
Django changing pdf font's xhtml2pdf
所以我正在将一个对象渲染为 pdf,我想更改我的 pdf 字体。
我的项目
myproject/
|-- myproject
|-- static/
|-- admin/
|-- fonts/
|-- GothamPro-Medium.eot
|-- GothamPro-Medium.ttf
|-- GothamPro-Medium.woff
|-- GothamPro-Medium.woff2
我的page.html
<style type="text/css">
@page {
size: A4;
}
@font-face {
font-family: 'GothamPro-Medium';
src: url('static/admin/fonts/GothamPro-Medium.woff') format('woff'),
url('static/admin/fonts/GothamPro-Medium.woff2') format('woff2'),
url('static/admin/fonts/GothamPro-Medium.eot?') format('eot'),
url('static/admin/fonts/GothamPro-Medium.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
body {
font-family: 'GothamPro-Medium';
}
</style>
<body>
TESTE
</body>
我的字体不工作,我已经用另一种字体试过了,但什么都没有
使用/static/admin/fonts/GothamPro-Medium.woff
在此处添加 setting.py
STATIC_URL = '/static/'
然后在模板中
将此添加到 html 文件
的顶部
{% load static %}
并使用
url({% static 'admin/fonts/GothamPro-Medium.ttf' %})
而不是 url('static/admin/fonts/GothamPro-Medium.ttf')
所以我正在将一个对象渲染为 pdf,我想更改我的 pdf 字体。
我的项目
myproject/
|-- myproject
|-- static/
|-- admin/
|-- fonts/
|-- GothamPro-Medium.eot
|-- GothamPro-Medium.ttf
|-- GothamPro-Medium.woff
|-- GothamPro-Medium.woff2
我的page.html
<style type="text/css">
@page {
size: A4;
}
@font-face {
font-family: 'GothamPro-Medium';
src: url('static/admin/fonts/GothamPro-Medium.woff') format('woff'),
url('static/admin/fonts/GothamPro-Medium.woff2') format('woff2'),
url('static/admin/fonts/GothamPro-Medium.eot?') format('eot'),
url('static/admin/fonts/GothamPro-Medium.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
body {
font-family: 'GothamPro-Medium';
}
</style>
<body>
TESTE
</body>
我的字体不工作,我已经用另一种字体试过了,但什么都没有
使用/static/admin/fonts/GothamPro-Medium.woff
在此处添加 setting.py
STATIC_URL = '/static/'
然后在模板中 将此添加到 html 文件
的顶部{% load static %}
并使用
url({% static 'admin/fonts/GothamPro-Medium.ttf' %})
而不是 url('static/admin/fonts/GothamPro-Medium.ttf')