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

Inherited style attributes from parent element is not being applied. #2244

Closed
codehunter1992 opened this issue Aug 30, 2024 · 28 comments
Closed

Comments

@codehunter1992
Copy link

codehunter1992 commented Aug 30, 2024

Inherited style attributes from parent element is being ignored when builds PDF.

For example,

<span style="font-family: 'comic sans ms', sans-serif'; font-size: 16px;">
    Hello world, welcome to <strong>WeasyPrint</strong>.
</span>

Word "WeasyPrint" in rendered PDF, has no correct font family and size.

Is there any solution?

@liZe
Copy link
Member

liZe commented Aug 30, 2024

Hi!

Do you have bold Comic Sans installed on your system?

@codehunter1992
Copy link
Author

Yes, since if I apply bold to entire sentence like <strong><span style="font-family: 'comic sans ms', sans-serif'; font-size: 16px;">Hello world, welcome to WeasyPrint</span></strong>, it works properly.

@liZe
Copy link
Member

liZe commented Aug 30, 2024

Could you please share your PDF with the wrong font?

@codehunter1992
Copy link
Author

1725022933811.pdf
This is the PDF file.
The words Lorem Ipsum, dummy text (read color), Lorem Ipsum (underline) are all should have same font family and size.

@liZe
Copy link
Member

liZe commented Aug 30, 2024

Your original example works for me (when I remove the extra quote).

ms.pdf

Your PDF seems to be rendered using an old version of WeasyPrint. Could you try a recent version?

@codehunter1992
Copy link
Author

I upgraded Weasyprint version 62.3

This is my html code:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
</head>
<body>
   <p><span style="font-family: 'comic sans ms', sans-serif; font-size: 18pt;">Hello world, welcome to <strong>WeasyPrint</strong>.</span></p>
 <body>
</html>

This is generated PDF file using the latest version of package.
be2d30e4-fbe2-44e2-ac04-9e55cab1de6e.pdf

I also tried to test without html wrapper, same issue.

@liZe
Copy link
Member

liZe commented Aug 30, 2024

It works for me. I really do think that you don’t have the bold font installed, it was automatically generated with older versions of WeasyPrint, but it’s not anymore (#1470).

What’s your OS, and how did you install Comic Sans?

@codehunter1992
Copy link
Author

I am using MacOS 14.3.1.
I didn't install the font myself, I just guessed that the font was installed because below html works properly.

<strong><span style="font-family: 'comic sans ms', sans-serif'; font-size: 16px;">Hello world, welcome to WeasyPrint</span></strong>

@liZe
Copy link
Member

liZe commented Aug 30, 2024

Could you please share the PDF generated with this HTML?

@codehunter1992
Copy link
Author

Here you go the PDF file.
1725025244839.pdf

@liZe
Copy link
Member

liZe commented Aug 30, 2024

Well, it’s installed, and the documentation says it’s installed by default. To be honest, I have no idea why it doesn’t work for you. Do you have the same problem with other fonts? You can try with Futura or Didot, for example.

@codehunter1992
Copy link
Author

Same issue with another font.
For example:
<p><span style="font-family: tahoma, arial, helvetica, sans-serif; font-size: 18pt;">Hello world, welcome to <strong>WeasyPrint</strong>.</span></p>

<p><span style="font-family: arial, helvetica, sans-serif; font-size: 18pt;">Hello world, welcome to <strong>WeasyPrint</strong>.</span></p>

All didn't work. :(

@codehunter1992
Copy link
Author

Well, it’s installed, and the documentation says it’s installed by default. To be honest, I have no idea why it doesn’t work for you. Do you have the same problem with other fonts? You can try with Futura or Didot, for example.

You said "it doesn't work for you".
Does this mean it works from your side?
If so, what is your Weasyprint version and OS? Can I know?

@liZe
Copy link
Member

liZe commented Aug 30, 2024

Does this mean it works from your side?

Yes, it does work for me.

ms.pdf

If so, what is your Weasyprint version and OS? Can I know?

I use version 62.3 on Linux.

Did you install WeasyPrint with Homebrew?

@codehunter1992
Copy link
Author

No, I installed using pip and running it in python project.
What is your version number of Linux?
Since I run a server on Ubuntu 20 and got same issue on it.

@liZe
Copy link
Member

liZe commented Aug 30, 2024

It works for me on latest Gentoo and Ubuntu computers. I’ve never seen this problem before, on countless Linux distributions. And it’s never been reported, as far as I can remember.

Since I run a server on Ubuntu 20 and got same issue on it.

It’s really unlikely this error could happen on a fresh Ubuntu 20.04 install, or we would have spotted this before. Is there any specific configuration (maybe a Fontconfig configuration) you may have on both computers?

No, I installed using pip and running it in python project.

On MacOS, how did you install the non-Python dependencies, such as Pango and Fontconfig?

@codehunter1992
Copy link
Author

I have no any specific configuration regarding it.

I didn't install non-python dependencies such as Pango and Fontfonfig manually from MacOS. Nothing let me install them manually.

On Ubuntu, I installed Weasyprint 52.5 because of the dependencies' version conflicts.

@liZe
Copy link
Member

liZe commented Aug 30, 2024

I didn't install non-python dependencies such as Pango and Fontfonfig manually from MacOS. Nothing let me install them manually.

Then they were already installed by another application, maybe with older broken versions.

The only documented way to make WeasyPrint work is to use Homebrew, and unfortunately we can’t help you much if you used anything else. You should try with Homebrew, as it’s known to work.

On Ubuntu, I installed Weasyprint 52.5 because of the dependencies' version conflicts.

Just to be sure, could you please write ms.html with

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
</head>
<body>
   <p><span style="font-family: 'comic sans ms', sans-serif; font-size: 18pt;">Hello world, welcome to <strong>WeasyPrint</strong>.</span></p>
 <body>
</html>

then try:

sudo apt install weasyprint
weasyprint --info
weasyprint ms.html ms.pdf

and share your PDF?

@codehunter1992
Copy link
Author

I did tested on MacOS with this command line - weasyprint ms.html ms.pdf (not in python project) and it generates PDF file properly without any issue.

html = HTML(string=html_string, encoding="utf-8")
page_formatter = CSS(string="@page { size: A4; margin: 0.75in }", encoding="utf-8")
page_stylesheet = CSS(filename=f"{MEDIA_ROOT}assets/document_template/style.css")
html.write_pdf(
    MEDIA_ROOT + self.file_path, stylesheets=[page_formatter, page_stylesheet], presentational_hints=True
)

These are my python code to generate PDF from html string.
Any code line may occur such issue do you think?

@liZe
Copy link
Member

liZe commented Aug 30, 2024

I did tested on MacOS with this command line - weasyprint ms.html ms.pdf (not in python project) and it generates PDF file properly without any issue.

👍

Any code line may occur such issue do you think?

It’s hard to tell without the whole code, but maybe using a shared FontConfiguration will help?

@codehunter1992
Copy link
Author

codehunter1992 commented Aug 30, 2024

On Ubuntu - by running sudo apt install weasyprint I got this.

Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package weasyprint

(Sorry, I just noticed that I run Ubuntu server OS 18.04)

By running weasyprint --info returns me weasyprint: command not found

After activate python venv, it returns me

System: Linux
Machine: x86_64
Version: #115~18.04.1-Ubuntu SMP Mon May 22 20:06:37 UTC 2023
Release: 5.4.0-1109-azure

WeasyPrint version: 52.5
Python version: 3.9.12
Cairo version: 11510
Pango version: 14014
CairoSVG version: 2.7.1

weasyprint ms.html ms.pdf generates a pdf file, but font doesn't work in entire html code.
ms.pdf

@liZe
Copy link
Member

liZe commented Aug 30, 2024

Version: #115~18.04.1-Ubuntu

That’s Ubuntu 18.04, not 20.04. WeasyPrint is not packaged for 18.04, let’s test with venv then.

weasyprint ms.html ms.pdf generates a pdf file, but font doesn't work in entire html code.

You have to install Comic Sans MS. Should work with sudo apt install ttf-mscorefonts-installer.

@codehunter1992
Copy link
Author

Yes, after install ttf-mscorefonts-installer, weasyprint ms.html ms.pdf generates PDF correctly.
Thanks.
But I need to make python project work :)
Any other more suggestions?

@liZe
Copy link
Member

liZe commented Aug 30, 2024

Any other more suggestions?

Did you try the shared FontConfiguration as explained above?

Otherwise, it means that something specific to your project breaks WeasyPrint. You probably know better what your project does, so we can’t really help you about that :/.

@codehunter1992
Copy link
Author

OK, Thanks, I will try more myself, and keep posted here.
You can also update once you get a new idea.

@liZe
Copy link
Member

liZe commented Aug 30, 2024

You can also update once you get a new idea.

I really don’t know what can cause this issue.

@liZe
Copy link
Member

liZe commented Sep 17, 2024

@codehunter1992 Did you find anything interesting about this issue?

@codehunter1992
Copy link
Author

It was a silly issue.
There was a bad line in the css file that I used to generate to PDF.
After remove that line from css, it works properly.
Thank you for your attention.

@liZe liZe closed this as not planned Won't fix, can't repro, duplicate, stale Sep 18, 2024
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

2 participants