Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fonts not embedded in PDF #1318

Closed
slartibart70 opened this issue Mar 22, 2021 · 14 comments
Closed

Fonts not embedded in PDF #1318

slartibart70 opened this issue Mar 22, 2021 · 14 comments
Labels
bug Existing features not working as expected
Milestone

Comments

@slartibart70
Copy link

slartibart70 commented Mar 22, 2021

Hi,
i was using weasyprint 52.2 with python 3.8 on fedora32.
After upgrading to fedora33, my fonts are not embedded into the resulting pdf any more.
fedora33 uses python 3.9, i also upgraded to weasyprint 52.4... no change to the result.

What i did so far:

  1. using weasyprint standalone (this is my main usage)
weasyprint in.html out.pdf

A pdf is generated, embedded fonts missing

  1. using weasyprint as python script
from weasyprint import HTML, CSS
from weasyprint.fonts import FontConfiguration
font_config = FontConfiguration()
html=HTML('in.md.html')
html.write_pdf('out.pdf',font_config=font_config)

same result, no fonts in pdf

My Html uses an external css with @font-face
e.g.

@font-face {
  font-family: mySerif;
    font-weight: normal;
    font-style: normal;
    font-stretch: normal;
  src: local('Liberation Serif'),
       url(file:///usr/share/fonts/liberation-serif/LiberationSerif-Regular.ttf) format('truetype');
}

The browser has no problems rendering my embedded fonts, neither did weasyprint on fedora32/py3.8 (if that matters at all...)
So, my old working pdf output had these fonts (successfully embedded)

name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
AOAFFM+LiberationSerif               TrueType          WinAnsi          yes yes yes     36  0
VZUWYF+LiberationSerif               CID TrueType      Identity-H       yes yes yes     37  0
DIVSUD+RobotoMono-Regular            TrueType          WinAnsi          yes yes yes     84  0
JPSGLH+CairoFont-2-0                 Type 1C           WinAnsi          yes yes yes     85  0
HNYAUK+RobotoMono-Bold               TrueType          WinAnsi          yes yes yes    112  0
IQFZUN+RobotoMono-Regular            TrueType          WinAnsi          yes yes yes    113  0

The new one has only these default fonts:

name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
ANQKNJ+BitstreamVeraSans-Roman       TrueType          WinAnsi          yes yes yes     37  0
JBCTMJ+DejaVuSans                    CID TrueType      Identity-H       yes yes yes     38  0
XMKNHA+BitstreamVeraSans-Roman       CID TrueType      Identity-H       yes yes yes     83  0
YNMLOL+BitstreamVeraSans-Bold        TrueType          WinAnsi          yes yes yes     84  0
EZEEOY+BitstreamVeraSans-Oblique     TrueType          WinAnsi          yes yes yes    122  0

I had a (one!) font embedded into my pdf when using

weasyprint -v ${filename}.md.html ${filename}.md.pdf -s <(echo 'body { font-family: 'Liberation Serif' !important }')

with this font list:

name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
MNDGRP+LiberationSerif               TrueType          WinAnsi          yes yes yes     37  0
RLFUEA+LiberationSerif               CID TrueType      Identity-H       yes yes yes     38  0
AFSQCL+BitstreamVeraSans-Roman       TrueType          WinAnsi          yes yes yes     39  0
WKPJBS+LiberationSerif-Bold          TrueType          WinAnsi          yes yes yes     87  0
YTXGBQ+BitstreamVeraSans-Bold        TrueType          WinAnsi          yes yes yes    114  0
EZEEOY+BitstreamVeraSans-Oblique     TrueType          WinAnsi          yes yes yes    115  0

Overriding with user styelsheets and !important cannot be the solution...
I'm running out of ideas for now, any help?

@liZe
Copy link
Member

liZe commented Mar 23, 2021

I'm running out of ideas for now, any help?

Hi!

You can try to launch weasyprint with the --verbose option and see if WeasyPrint complains about fonts.

@slartibart70
Copy link
Author

i did,
it's complaining about some css rules coming from pandoc (screen related), but nothing serious:

INFO: Step 1 - Fetching and parsing HTML - in.md.html
INFO: Step 2 - Fetching and parsing CSS - CSS string
INFO: Step 2 - Fetching and parsing CSS - CSS string
WARNING: Ignored `text-decoration: inherit` at 11:46, invalid value.
WARNING: Ignored `user-select: none` at 31:32, unknown property.
INFO: Step 2 - Fetching and parsing CSS - file:///home/user/.pandoc/pandoc4.css
INFO: Step 3 - Applying CSS
INFO: Step 4 - Creating formatting structure
INFO: Step 5 - Creating layout - Page 1
INFO: Step 5 - Creating layout - Page 2
INFO: Step 5 - Creating layout - Page 3
INFO: Step 5 - Creating layout - Page 4
INFO: Step 5 - Creating layout - Page 5
INFO: Step 5 - Creating layout - Page 6
INFO: Step 5 - Creating layout - Page 7
INFO: Step 5 - Creating layout - Page 8
INFO: Step 5 - Creating layout - Page 9
INFO: Step 5 - Creating layout - Page 10
INFO: Step 5 - Creating layout - Page 11
INFO: Step 5 - Creating layout - Page 12
INFO: Step 5 - Creating layout - Page 13
INFO: Step 5 - Creating layout - Page 14
INFO: Step 5 - Creating layout - Page 15
INFO: Step 5 - Creating layout - Page 16
INFO: Step 5 - Creating layout - Page 17
INFO: Step 5 - Creating layout - Page 18
INFO: Step 5 - Creating layout - Page 19
INFO: Step 6 - Drawing
INFO: Step 7 - Adding PDF metadata

@liZe
Copy link
Member

liZe commented Mar 23, 2021

Could you try to remove the local() part of your @font-face rules?

@slartibart70
Copy link
Author

slartibart70 commented Mar 23, 2021

did that already... no change

@liZe
Copy link
Member

liZe commented Mar 23, 2021

Well… Could you share your HTML file, so that I can try to reproduce?

@slartibart70
Copy link
Author

i made a stripped down version of the doc
I would expect the fonts to appear embedded in the pdf so that it looks like the html rendering in a browser
Thanks for your help!
test.zip

@liZe
Copy link
Member

liZe commented Mar 23, 2021

It works for me…

I really don’t know what could go wrong without a warning in the logs :/.

Another possible problem: do you have the latest version of tinycss2 (1.1.0)? Otherwise, url() with no quotes doesn’t work well.

@slartibart70
Copy link
Author

slartibart70 commented Mar 23, 2021

nice to hear, but doesn't help me here :-)

I installed using pip, seems up-to date?
and i have put quotes around the urls.. still no change

$ pip list  --user
Package    Version
---------- -------
cairocffi  1.2.0
CairoSVG   2.5.2
cffi       1.14.5
cssselect2 0.4.1
pycairo    1.20.0
pycparser  2.20
Pyphen     0.10.0
tinycss2   1.1.0
WeasyPrint 52.4

@slartibart70
Copy link
Author

and i tried on a completely different fedora33 machine, there weasyprint was installed as root (i know....)
pycairo 1.18.2
is the only difference

So... i assume this has something to do with fedora33 then?
But what exactly?

@liZe
Copy link
Member

liZe commented Mar 23, 2021

pycairo 1.18.2
is the only difference

WeasyPrint doesn’t use Pycairo (it uses CairoCFFI instead).

I installed using pip, seems up-to date?

It is.

So... i assume this has something to do with fedora33 then?
But what exactly?

OMG. I know. Fedora has updated Pango to 1.48.3 10 days ago, you need this fix: 47043a1.

We’ll release (again) another 52.x version, because it will cause a lot of issues.

Please let us know if it fixes your problem. Thanks a lot for the bug report, that’s really useful to know early that the new version of Pango has already been included in some distributions.

@FelixSchwarz: you may be interested in this issue. Backporting 47043a1 or upgrading WeasyPrint to the next 52.x version looks like a good idea.

(And for SemVer lovers: Pango 1.48.3 actually broke WeasyPrint. That’s not their fault, that’s not our fault.)

@FelixSchwarz
Copy link
Contributor

@liZe Thanks for bringing this to my attention. I recently got an automated notification that WeasyPrint's test suite has even more test failures in Fedora but I did not have time to debug this.

@slartibart70
Copy link
Author

you're my hero!!!
Thanks for pointing to the patch, appllied it and we're back to 'normal' again!!

@FelixSchwarz
Copy link
Contributor

@slartibart70 if you are interested in helping out with Fedora's WeasyPrint, please let me know. ;-) Fedora uses very recent versions which means we spot problems (ideally) before/at the same time as upstream so fixing these is often upstream development. For example Fedora started to run test suites with Python 3.10 three months ago (and I have way too many bug reports about test failures with 3.10 waiting for me).

@slartibart70
Copy link
Author

@FelixSchwarz
well, i use weasyprint for technical docs i write (i really don't want to use a wordprocessor for that). My workflow ist markdown/pandoc/weasyprint, so any errors coming up i'll notice immediately.
Or do you think of running further testsuites here on fc33?

@liZe liZe added the bug Existing features not working as expected label Apr 14, 2021
@liZe liZe added this to the 52.5 milestone Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Existing features not working as expected
Projects
None yet
Development

No branches or pull requests

3 participants