Unable to integrate custom fonts and bold text when inserting text into PDFs using PyMuPDF #4824
Unanswered
jahnvi-sikligar-tcgls
asked this question in
Looking for help
Replies: 2 comments 5 replies
-
|
This is not an issue but a Discussions item: transferring ... |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
Using your own font requires specifying the name of the file or the its content in memory (font buffer). This must happen per page - not per PDF. Second you must specify the Best use this approach: font = pymupdf.Font(fontfile="path to font")
fontname = "mycoolfont" # this is NOT the font filename!
# once per page:
page.insert_font(fontname=fontname, fontbuffer=font.buffer)
# insert text with the font:
page.insert_textbox(..., fontname=fontname)Notes:
|
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I’m implementing a PDF personalization pipeline that uses
page.insert_textbox()to add personalized text to existing PDFs. While the text insertion works, custom fonts and bold styling consistently fail, even when trying different font registration and fallback strategies.PyMuPDF either:
silently ignores the requested custom font and falls back to Helvetica,
or raises an error if a non-built-in font name is passed.
The same issue occurs with bold text: setting the bold flag or using font names such as "helv-bold" or custom font files does not change the rendered output.
What I Expected
What Actually Happens
Code Sample
status = page.insert_textbox( rect, text, fontsize=fs, fontname=fontname, # custom fonts or bold variants fail align=0, color=text_color )Do let me know if any more details are needed.
Beta Was this translation helpful? Give feedback.
All reactions