-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 11 replies
-
Answering directly here - then I will transfer this to "Discussions", where we may handle any additional questions. Ad (1) The displayed fontname as you are showing it probably is incomplete, because most creator software will build font subsets - resulting in an extended name like "ABCDEF+CMMI7". The first 6 characters are random, so you must extract the text after setting a global parameter which causes returning the full subset name in text extraction. Once you know this name, inspect this output to find the font xref: In [4]: page.get_fonts()
Out[4]:
[(12, 'cff', 'Type1', 'EAMKOQ+FrutigerLT-Roman', 'T1_0', 'WinAnsiEncoding'),
(14, 'cff', 'Type1', 'DWXEAS+FrutigerLT-Bold', 'T1_1', 'WinAnsiEncoding'),
(15,
'cff',
'Type1',
'CXIYMU+AGaramondPro-Regular',
'T1_2',
'WinAnsiEncoding')]
In [5]: # access font buffer of xref 12 and make a font of it
In [6]: ff = doc.extract_font(12)
In [7]: fontbuffer = ff[-1]
In [8]: myfont = fitz.Font(fontbuffer=fontbuffer)
In [9]: myfont
Out[9]: Font('FrutigerLT-Roman Regular')
In [10]: myfont.flags
Out[10]:
{'mono': False,
'serif': True,
'bold': False,
'italic': False,
'substitute': False,
'stretch': False,
'fake-bold': False,
'fake-italic': False,
'opentype': False,
'invalid-bbox': False,
'cjk': False,
'cjk-lang': None,
'embed': True,
'never-embed': False} Setting the global variable for returning the full subset font name: Then you can use BUT beware that these are subset fonts: not all characters of the full fonts will be present - that's the whole motivation behind subsets, isn't it. So if your output text contains unsupported characters you will see spaces there. Ad (2) Font weights (bold) and styles (italic) generally are part of different fontfiles. If you text contains a mixture of regular and these other variations, you must undertake the effort to make different text pieces yourself - each with its own font (variant). This is tedious with But there is an elegant solution available now in PyMuPDF: use the new |
Beta Was this translation helpful? Give feedback.
Answering directly here - then I will transfer this to "Discussions", where we may handle any additional questions.
This is not issue / bug.
Ad (1)
The displayed fontname as you are showing it probably is incomplete, because most creator software will build font subsets - resulting in an extended name like "ABCDEF+CMMI7". The first 6 characters are random, so you must extract the text after setting a global parameter which causes returning the full subset name in text extraction. Once you know this name, inspect this output to find the font xref: