Detecting bold fonts in a pdf #3779
-
To check whether the text inside a span is bold or not, i usually check if 'bold' exists in span['font'] (font name) or not. But in the attached pdf bdh_single.pdf, all the font's are "SourceSansPro-Regular". When looking at the pdf, you can clearly see that some text (headings) are bold. In such cases, how do i find if some text is bold or not? For font names, i look at the ouput of this code: doc = fitz.open("bdh_single.pdf") blocks = page.get_text("dict")["blocks"] |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Of course, PyMuPDF has no way of visually determining how a glyph looks like for the human eye: it is dependent on what the font itself tells us about its properties. Some PDF creators use tricks in an effort to achieve text effects without embedding another font. |
Beta Was this translation helpful? Give feedback.
Just had another look:
This PDF uses PDF command
2 Tr
which means "Set text rendering mode 2":So if fill and stroke color are the same (e.g. black) then - with a suitable line width - characters written like that appear bold, while still the same font is used.