FPDF 第二次运行,崩溃

问题描述

我使用下面的代码生成月度报告。当我需要获取两个不同月份的报告时,正确创建了第一个月,然后我更改了月份并重新启动程序。输出时,fpdf 会随着您在下面看到的回溯而崩溃 要获得两个月的报告,我必须创建第一个报告,完全退出 py 程序,重新启动并创建第二个报告。

从我在回溯中看到的内容来看,它似乎没有找到任何图像,但它们与第一个报告中使用的图像相同

class Build_Pdf(FPDF):

    table = ''
pdf = FPDF('L','mm','A4')
pdf.alias_nb_pages()

def top(year,meonth,table):
    pdf.add_font('IndieFlower-Regular','','/usr/.local/share/fonts/IndieFlower-Regular.ttf',uni=True)
    write_year = 'Reference: ' + month + ' ' + year
    pdf.add_page()
    pdf.image('/opt/rambo/logo.jpg',25,8,30)
    pdf.set_font('IndieFlower-Regular',15)
    pdf.set_y(50)
    pdf.set_x(15)
    pdf.cell(50,7,write_year,1,'L')
    pdf.image('/opt/rambo/gg.png',65,30,15)
    return



def create_Pdf(year,month):
    global error,none
    month = Functions.convert_month_number[month]
    check = check_table(year,month,daysinmonth,table = 'tiMetable')
    if check is not 0:
        go_Pdf (year,table = 'tiMetable')
    [...]
    pdffile = '/media/hdb1/temp/Location.pdf'
    if os.path.exists(pdffile):
        os.remove(pdffile)
    pdf.output(pdffile,'F')
    pdf.close()
    msg = QMessageBox()
    msg.setIcon(QMessageBox.information)
    msg.setText("Pdf file is in /media/hdb1/temp/Location.pdf")
    msg.exec_()
    return
    
    
Traceback (most recent call last):
  File "../PycharmProjects/SecondOne/index.py",line 333,in MakePdf
    Create_Pdf(year,month)
  File "../PycharmProjects/SecondOne/makepdfhour_data.py",line 86,in Create_Pdf
    pdf.output(pdffile,'F')
  File ".../fpdf/fpdf.py",line 1065,in output
    self.close()
  File ".../fpdf/fpdf.py",line 246,in close
    self._enddoc()
  File ".../fpdf/fpdf.py",line 1637,in _enddoc
    self._putresources()
  File ".../fpdf/fpdf.py",line 1585,in _putresources
    self._putimages()
  File ".../fpdf/fpdf.py",line 1515,in _putimages
    del info['data']
KeyError: 'data'

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)