Search code examples
htmlcssdjangoxhtml2pdf

wrong attributes for <pdf:font> xhtml2pdf


I am trying to specify a font for my xhtml2pdf file. By i get this error wrong attributes for <pdf:font>

I am not sure the correct way to specify the attributes for the font?

I have tried searching for a solution to this, but can't find anything.

<!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>

Solution

  • According to the documentation on custom fonts xhtml2pdf only accepts TrueType font or a Postscript font. You are trying to use OTF.

    Try converting your font to TTF or Postscript.