pyfpdf icon indicating copy to clipboard operation
pyfpdf copied to clipboard

list index out of range for unicode emojies

Open TimurNurlygayanov opened this issue 5 years ago • 8 comments

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

TimurNurlygayanov avatar Aug 24 '19 07:08 TimurNurlygayanov

What font can I use to cover Unicode (Russian, Ukraine) and emojis?

TimurNurlygayanov avatar Aug 24 '19 07:08 TimurNurlygayanov

same error, have u fixed it?

luckydog5 avatar Aug 28 '19 09:08 luckydog5

same error

kavigupta avatar Jul 17 '20 09:07 kavigupta

Same error and no ideas on how to fix it.

andrei-polukhin avatar Dec 06 '20 19:12 andrei-polukhin

How to fix this error?

lukasloetkolben avatar Dec 16 '20 09:12 lukasloetkolben

It's sad it ain't possible yet :loudly_crying_face: :sob: \uD83D\uDE2D

aquatic7 avatar May 04 '21 00:05 aquatic7

Same error here....

robert2555 avatar Feb 24 '22 13:02 robert2555

pyfpdf is not maintained anymore, have you tried using fpdf2?

We support emojis since v2.4.3: https://pyfpdf.github.io/fpdf2/EmojisSymbolsDingbats.html

Lucas-C avatar Mar 01 '22 10:03 Lucas-C