Skip to content

write_html: read a CSS font-size with its unit, like browsers - #2034

Merged
andersonhc merged 1 commit into
py-pdf:masterfrom
RavSinghChandan:html-font-size-units
Oct 20, 2026
Merged

andersonhc merged 1 commit into
py-pdf:masterfrom
RavSinghChandan:html-font-size-units

Conversation

@RavSinghChandan

Copy link
Copy Markdown

<font style="font-size: 14pt"> or style="font-size: 12px" was silently ignored by write_html(): the value went through float(), which only accepts a bare number, so the text kept the previous size. Browsers apply the unit.

The value is now read with resolve_length(), the parser already used for table and image dimensions, so 14pt gives 14 pt, 12px 9 pt and 0.25in 18 pt. A number without a unit is still read as points, and values it can't convert (1.5em, larger) are still ignored, as before. Added tests comparing against the equivalent size attribute.

@andersonhc
andersonhc merged commit 485ca98 into py-pdf:master Oct 20, 2026
23 checks passed
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

Successfully merging this pull request may close these issues.

2 participants