首页 > 解决方案 > 错误的属性xhtml2pdf

问题描述

我正在尝试为我的xhtml2pdf文件指定字体。通过我得到这个错误wrong attributes for <pdf:font>

我不确定指定字体属性的正确方法?

我曾尝试寻找解决方案,但找不到任何东西。

<!DOCTYPE html>
<html>
<style>
@import url('https://fonts.googleapis.com/css2?family=Itim&display=swap');
</style>
<style>
@media print {
    .pagebreak { page-break-before: always; } /* page-break-after works, as well */
}

@page {
    size: a4;
    margin: 1cm;
    @frame footer {
        -pdf-frame-content: footerContent;
        bottom: 0cm;
        margin-left: 9cm;
        margin-right: 9cm;
        height: 1cm;
        }

@font-face {
  font-family: 'Itim', cursive;
  src: url('https://fonts.googleapis.com/css2?family=Itim&display=swap');
}
</style>
<body>
<p style="font-size:1.3rem;font-family: Itim,sans-serif;">We have generated your PDF!</p>
</body>

标签: htmlcssdjangoxhtml2pdf

解决方案


根据关于自定义字体的文档 xhtml2pdf只接受TrueType font or a Postscript font.您正在尝试使用OTF.

尝试将您的字体转换为TTFPostscript


推荐阅读