我正在用Django用xhtml2pdf创建一个PDF。我正在发送PDF去打印,但是他们说有些字体没有嵌入。我有一个Helvetica字体,但我没有在PDF中使用Helvetica。
下面是PDF属性的屏幕截图

如你所见,Guilles的‘ComicFont和TF2Secondary是正确嵌入的,但不是Helvetica。
下面是生成PDF的视图:
def generate_pdf(request, book, order):
try:
book = Book.objects.get(pk=int(book))
order = Order.objects.get(identificador=order, cuento=book)
except ObjectDoesNotExist:
raise Http404
data = {}
data = ast.literal_eval(order.datos_variables)
data['order'] = order
template = get_template(order.book.plantilla_html)
html = template.render(Context(data))
url = '/Users/vergere/dev/media/pdfs/%s.pdf' % order.identificador
fichero = open(url, "w+b")
pisaStatus = pisa.CreatePDF(html.encode('utf-8'), dest=fichero, encoding='utf-8')
fichero.seek(0)
fichero.close()
order.url_pdf = '%s.pdf' % order.identificador
order.contador_libro = numero
order.codigo_libro = country_code
order.save()
return HttpResponseRedirect(reverse('order_single', kwargs={'pedido': order.pk}))下面是我的HTML:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Background</title>
<style>
@page {
background-image: url("cuento1/img/portada.jpg");
size: 213mm 216mm;
}
@font-face {
font-family: Helvetica;
src: url(pdf_generator/helvetica.ttf);
}
@font-face {
font-family: 'Gilles';
src: url(pdf_generator/cuento1/gilles/gilles.ttf);
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'Secondary';
src: url(pdf_generator/cuento1/tf2_secondary/tf2_secondary.ttf);
font-weight: normal;
font-style: normal;
}
* {
box-shadow:none !important;
margin: 0;
padding: 0;
text-shadow: none !important;
font-family: 'Gilles';
}
body{
font-family: 'Gilles';
}
p {
color: #464439;
display: block;
font-weight: normal;
position: absolute;
}
.page-1 p, .page-2 p{
font-family: 'Secondary';
font-size: 40px;
line-height: 1.3em;
position: absolute;
}
</style>
</head>
<body>
<pdf:nextpage name="p1" />
<pdf:nextpage name="p2" />
<div class="page-6 page-dedicatoria">
{{order.dedicatoria}} <br /> {{order.de}}
</div>
<p> </p>
</body>
</html>有人知道为什么要使用Helvetica吗?或者有什么方法可以嵌入Helvetica?我正在尝试"@font-face“,但它不起作用。
发布于 2014-08-08 20:42:49
Helvetica是每个PDF渲染器都必须提供的标准字体之一。因此,它不需要嵌入。
一种可能的解决方案是使用另一种sans-serif字体而不是Helvetica。在windows上,例如Arial。在OSX上,例如Helvetica、Neue或Avenir。它们看起来很像Helvetica,但不是标准的PDF字体。
在样式表中,为所有元素指定新字体;
* {
font-family: Avenir;
}https://stackoverflow.com/questions/25203219
复制相似问题