-
Hi there. I ran the slightly modified example code from the documentation (How to Use Non-Standard Encoding) on two platforms.
import fitz
assert 'PyMuPDF 1.23.3:' in fitz.__doc__
doc=fitz.open()
page = doc.new_page()
shape = page.new_shape()
shape.insert_text((50,70), "Hello world!", fontname="HELV", encoding=fitz.TEXT_ENCODING_CYRILLIC)
shape.insert_text((50,90), "Привет world!", fontname="HELV", encoding=fitz.TEXT_ENCODING_CYRILLIC)
shape.insert_text((50,110), "Привет мир!", fontname="HELV", encoding=fitz.TEXT_ENCODING_CYRILLIC)
shape.commit()
doc.save("t.pdf") And I got the same results. How can I get the correct text in Cyrillic in PDF? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
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") |
Beta Was this translation helpful? Give feedback.
-
The only thing to watch out for: do not use the "reserved" names in "fontname" parameters like "helv". Do something like that "myhelv" stuff. |
Beta Was this translation helpful? Give feedback.
-
Thanks, it works! |
Beta Was this translation helpful? Give feedback.
-
I think we should adapt the documentation accordingly. You were seduced to follow a path that is not recommendable. |
Beta Was this translation helpful? Give feedback.
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:
Result: