简体   繁体   English

xhtml2pdf没有嵌入Helvetica

[英]xhtml2pdf doesn't embed Helvetica

I'm creating a PDF with xhtml2pdf using Django. 我正在使用Django用xhtml2pdf创建PDF。 I'm sending that PDF to print, but then they say that some Fonts are not embed. 我正在发送要打印的PDF,但是随后他们说某些字体没有被嵌入。 I have a Helvetica font, but I didn't use Helvetica in the PDFs. 我使用Helvetica字体,但在PDF中未使用Helvetica。

Here you have a Screen Shot of the properties of the PDF 这里是PDF属性的屏幕截图

在此处输入图片说明

As you see, Guilles'ComicFont and TF2Secondary are correclty embbeded, but not with Helvetica. 如您所见,Guilles'ComicFont和TF2Secondary已正确嵌入,但不适用于Helvetica。

Here you have my view that generates the PDF: 在这里,我有生成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}))

And here my HTML: 这是我的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>&nbsp;</p>
    </body>
</html>

Anyone knows why is using Helvetica? 谁知道为什么要使用Helvetica? Or there is any way to embed Helvetica? 或者有什么方法可以嵌入Helvetica? I'm trying with "@font-face" but It's not working. 我正在尝试使用“ @ font-face”,但无法正常工作。

Helvetica is one of the standard fonts that every PDF renderer has to have available. Helvetica是每个PDF渲染器都必须提供的标准字体之一。 Therefore it doesn't have to be embedded. 因此,它不必被嵌入。

A possible solution would be to use another sans-serif font instead of Helvetica. 一种可能的解决方案是使用另一种sans-serif字体代替Helvetica。 On windows eg Arial. 在Windows上,例如Arial。 On OSX eg Helvetica Neue or Avenir. 在OSX上,例如Helvetica Neue或Avenir。 They look a lot like Helvetica, but are not standard PDF fonts. 它们看起来很像Helvetica,但不是标准的PDF字体。

In your stylesheet, specify a new font for all elements; 在样式表中,为所有元素指定新字体;

* {
    font-family: Avenir;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM