Skip to content

Pdf insert_text with cyrilic encoding. #2687

Answered by JorjMcKie
vb64 asked this question in Q&A
Discussion options

You must be logged in to vote

I would avoid using the built-in Base-14 fonts. Try to use the file-based versions that also come with (Py-) MuPDF, which contain lots more of supported characters - beyond the 255 Unicode limits of Base-14.

Works like so:

import fitz

assert 'PyMuPDF 1.23.3:' in fitz.__doc__
font = fitz.Font("helv")  # looks exactly equal to its Base-14 brother
doc=fitz.open()
page = doc.new_page()
page.insert_font(fontname="myhelv", fontbuffer=font.buffer)
shape = page.new_shape()
shape.insert_text((50,70), "Hello world!", fontname="myhelv")
shape.insert_text((50,90), "Привет world!", fontname="myhelv")
shape.insert_text((50,110), "Привет мир!", fontname="myhelv")
shape.commit()
doc.save("t.pdf")

Result:

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by vb64
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@JorjMcKie
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2686 on September 25, 2023 11:49.