'FPDF output error python

I tried to create PDF report with some formatted string from database. Not sure what happened here. Is this issue related to the font? Also, what font would you recommend to cover more common languages including Asian languages and Latin languages. Your feedback will be extremely helpful.

def create_pdf(filename, text):
    pdf = FPDF()
    pdf.add_page()
    pdf.set_auto_page_break(auto=True)
    pdf.add_font('DejaVu', '', '/data/mlo/fonts/DejaVuSansCondensed.ttf', uni=True)
    pdf.set_font('DejaVu','',10)
    pdf.multi_cell(0, 5, text)
    pdf.output(filename,'F')

However, sometimes it failed to output the file with IndexError: list index out of range

File "pdf_reporting.py", line 86, in create_pdf
    pdf.output(filename,'F')
  File "/production/sweeper/persistent/virtualenv/local/lib/python2.7/site-packages/fpdf/fpdf.py", line 1065, in output
    self.close()
  File "/production/sweeper/persistent/virtualenv/local/lib/python2.7/site-packages/fpdf/fpdf.py", line 246, in close
    self._enddoc()
  File "/production/sweeper/persistent/virtualenv/local/lib/python2.7/site-packages/fpdf/fpdf.py", line 1637, in _enddoc
    self._putresources()
  File "/production/sweeper/persistent/virtualenv/local/lib/python2.7/site-packages/fpdf/fpdf.py", line 1584, in _putresources
    self._putfonts()
  File "/production/sweeper/persistent/virtualenv/local/lib/python2.7/site-packages/fpdf/fpdf.py", line 1315, in _putfonts
    self._putTTfontwidths(font, ttf.maxUni)
  File "/production/sweeper/persistent/virtualenv/local/lib/python2.7/site-packages/fpdf/fpdf.py", line 1448, in _putTTfontwidths
    if (font['cw'][cid] == 0):
IndexError: list index out of range


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source