xhtml2pdf不会嵌入Helvetica [英] xhtml2pdf doesn't embed Helvetica
问题描述
我正在使用Django用xhtml2pdf创建PDF.我正在发送要打印的PDF,但是随后他们说未嵌入某些字体.我有Helvetica字体,但在PDF中没有使用Helvetica.
I'm creating a PDF with xhtml2pdf using Django. I'm sending that PDF to print, but then they say that some Fonts are not embed. I have a Helvetica font, but I didn't use Helvetica in the PDFs.
这里有PDF属性的屏幕截图
Here you have a Screen Shot of the properties of the PDF
如您所见,Guilles'ComicFont和TF2Secondary被嵌入,但与Helvetica无关.
As you see, Guilles'ComicFont and TF2Secondary are correclty embbeded, but not with Helvetica.
在这里,我具有生成PDF的视图:
Here you have my view that generates the 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",但无法正常工作.
Anyone knows why is using Helvetica? Or there is any way to embed Helvetica? I'm trying with "@font-face" but It's not working.
推荐答案
Helvetica是每个PDF渲染器都必须提供的标准字体之一.因此,不必将其嵌入.
Helvetica is one of the standard fonts that every PDF renderer has to have available. Therefore it doesn't have to be embedded.
可能的解决方案是使用另一种sans-serif字体代替Helvetica.在Windows上阿里亚尔在OSX上,例如Helvetica Neue或Avenir.它们看起来很像Helvetica,但不是标准的PDF字体.
A possible solution would be to use another sans-serif font instead of Helvetica. On windows e.g. Arial. On OSX e.g. Helvetica Neue or Avenir. They look a lot like Helvetica, but are not standard PDF fonts.
在样式表中,为所有元素指定一种新字体;
In your stylesheet, specify a new font for all elements;
* {
font-family: Avenir;
}
这篇关于xhtml2pdf不会嵌入Helvetica的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!