pyfpdf
pyfpdf copied to clipboard
list index out of range for unicode emojies
fpdf can't ignore characters which can't print, simple example:
# font was taken here: https://fonts2u.com/symbola.font
from fpdf import FPDF
def txt_to_pdf(text, CV_file):
pdf = FPDF()
pdf.add_page()
pdf.add_font('Symbola', '', 'fonts/Symbola_hint.ttf', uni=True)
pdf.set_font('Symbola', style='', size=12)
pdf.write(8, text)
pdf.ln(8)
pdf.output(CV_file, 'F')
text = '😉✌'
txt_to_pdf(text, 'test.pdf')
I've got the following error:
Traceback (most recent call last):
File "test_pdf.py", line 25, in <module>
txt_to_pdf(text, 'test.pdf')
File "test_pdf.py", line 21, in txt_to_pdf
raise e
File "test_pdf.py", line 18, in txt_to_pdf
pdf.output(CV_file, 'F')
File "/usr/local/lib/python3.7/site-packages/fpdf/fpdf.py", line 1065, in output
self.close()
File "/usr/local/lib/python3.7/site-packages/fpdf/fpdf.py", line 246, in close
self._enddoc()
File "/usr/local/lib/python3.7/site-packages/fpdf/fpdf.py", line 1637, in _enddoc
self._putresources()
File "/usr/local/lib/python3.7/site-packages/fpdf/fpdf.py", line 1584, in _putresources
self._putfonts()
File "/usr/local/lib/python3.7/site-packages/fpdf/fpdf.py", line 1315, in _putfonts
self._putTTfontwidths(font, ttf.maxUni)
File "/usr/local/lib/python3.7/site-packages/fpdf/fpdf.py", line 1448, in _putTTfontwidths
if (font['cw'][cid] == 0):
IndexError: list index out of range
What font can I use to cover Unicode (Russian, Ukraine) and emojis?
same error, have u fixed it?
same error
Same error and no ideas on how to fix it.
How to fix this error?
It's sad it ain't possible yet :loudly_crying_face: :sob: \uD83D\uDE2D
Same error here....
pyfpdf
is not maintained anymore, have you tried using fpdf2
?
We support emojis since v2.4.3: https://pyfpdf.github.io/fpdf2/EmojisSymbolsDingbats.html