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

@font-face declared fonts not embedded in pdf #54

Closed
oliverbienert opened this issue Sep 6, 2021 · 5 comments
Closed

@font-face declared fonts not embedded in pdf #54

oliverbienert opened this issue Sep 6, 2021 · 5 comments

Comments

@oliverbienert
Copy link

Hello, I recently started using django-weasyprint in a project to produce nice pdf-reports. However, the fonts I declared in my css using @font-face rules were not embedded in the final pdf.
This is probably due to a missing font_config attribute when django-weasyprint instanciates css objects. According to weasyprint docs, you should declare the font-config attribute also on css instance when using font-face rules. I tested it by writing a function view that directly uses weasyprint.
So I downloaded the latest stable version of django-weasyprint and fixed it locally. I'll create a pull request.

The output of pdffonts command before the fix:

name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
QHAAMN+DejaVuSans-Bold               TrueType          WinAnsi          yes yes yes      6  0
AYDOZU+DejaVuSans-ExtraLight         TrueType          WinAnsi          yes yes yes      7  0
UJBTBB+DejaVuSans                    TrueType          WinAnsi          yes yes yes      8  0

and after the fix:

name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
BQMJZP+FiraSans-Bold                 Type 1C           WinAnsi          yes yes yes      6  0
FTQEDP+FiraSans-Light                Type 1C           WinAnsi          yes yes yes      7  0
KUVOMO+FiraSans-Regular              Type 1C           WinAnsi          yes yes yes      8  0

Regards Oliver

oliverbienert added a commit to oliverbienert/django-weasyprint that referenced this issue Sep 6, 2021
@fdemmer
Copy link
Owner

fdemmer commented Oct 26, 2021

Thank you for your pull-request! I agree with @foarsitter and prefer keeping the get_font_config method.

Please check out the solution in the develop branch. Does this work for you?

@oliverbienert
Copy link
Author

Sorry for my late response. I checked it out, but now I've the problem that Weasyprint requires pango >= 1.44. I still run Buster, so I am going to dist-upgrade, then come back here.

@foarsitter
Copy link
Contributor

Bullseye will indeed solve the pango issue.

@oliverbienert
Copy link
Author

oliverbienert commented Oct 27, 2021

Now running Bullseye and everything looks great so far. Your solution works for me, my fonts are now correctly embedded as shown below:

name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
IUFVIR+FiraSans                      CID Type 0C (OT)  Identity-H       yes yes yes     22  0
DYGETD+FiraSans                      CID Type 0C (OT)  Identity-H       yes yes yes     26  0
BKZRLP+FiraSans                      CID Type 0C (OT)  Identity-H       yes yes yes     30  0

The pdffonts output looks a bit different to the one shown above in my first post, though, as it does not show the font-weight anymore in the name column and the type and encoding columns also differ. But my PDF looks nice, so I don't care.
Thank you for your work!
Regards Oliver

@fdemmer
Copy link
Owner

fdemmer commented Oct 28, 2021

thank you for verifying! fix released...

@fdemmer fdemmer closed this as completed Oct 28, 2021
fdemmer added a commit that referenced this issue Feb 24, 2022

Verified

This commit was signed with the committer’s verified signature.
fdemmer Florian Demmer
fdemmer added a commit that referenced this issue Feb 24, 2022

Verified

This commit was signed with the committer’s verified signature.
fdemmer Florian Demmer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants