【发布时间】:2021-07-14 13:08:04
【问题描述】:
我使用下面的代码生成月度报告。当我需要获取两个不同月份的报告时,第一个月被正确创建,然后我更改月份并重新启动程序。输出后,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, 0, 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, month, 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'
【问题讨论】: