question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WOFF font not included in PDF

See original GitHub issue

If I follow the example below but use a WOFF font.

font-face is parsed correctly but the actual font file is NOT included in the PDF, resulting in output with “missing unicode characters” blocks…

Documentation claims any FreeType font format should be supported.

from weasyprint import HTML, CSS
from weasyprint.fonts import FontConfiguration

font_config = FontConfiguration()
html = HTML(string='<h1>The title</h1>')
css = CSS(string='''
    @font-face {
        font-family: Gentium;
        src: url(http://example.com/fonts/Gentium.otf);
    }
    h1 { font-family: Gentium }''', font_config=font_config)
html.write_pdf(
    '/tmp/example.pdf', stylesheets=[css],
    font_config=font_config)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
liZecommented, Oct 21, 2020

As far as I can remember, WOFF (and now WOFF2) fonts are supported by FreeType, but for some reason they’re not included in the PDF, probably because of Cairo. It’s sad because FreeType doesn’t complain, Cairo doesn’t complain, and everything works as if the font could be embedded. At least when the format is not supported we have a warning and we can get another fallback format if possible…

This will be solved when Cairo is replaced by another library (you can follow #1232 for more news about this topic).

0reactions
liZecommented, Oct 27, 2020

WOFF and WOFF2 support has been disabled for the next release (52), with a clean fallback to other formats if possible. Documentation has been fixed too. Unless someone finds a better solution, we’ll have to wait for version 53 (without Cairo) to have WOFF fonts supported by WeasyPrint.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PDF fonts, Adobe Acrobat
Follow these steps in Adobe Acrobat to embed and substitute fonts in PDFs, and preview PDFs without local fonts.
Read more >
The Missing Guide to Font Formats: TTF, OTF, WOFF, EOT ...
The Missing Guide to Font Formats: TTF, OTF, WOFF, EOT & SVG ... that specifies if the author allows embedding of the font...
Read more >
The Web Open Font Format (WOFF) - Developer guides | MDN
WOFF (the Web Open Font Format) is a web font format developed by Mozilla in concert with Type Supply, LettError, and other organizations....
Read more >
Flying saucer does not load font from googleapis font css in ...
The old version of iText used by Flying Saucer doesn't support Web Open Font Format (WOFF) fonts. Support for such fonts was only...
Read more >
How to set a font in a PDF document | Piotr Horzycki
The so-called “web fonts” are usually compressed with a WOFF2 format which is not supported by PDF. Google Fonts, a popular web font...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found