向PDF rep添加多个事件

2024-05-08 23:37:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用FPDF创建一个pdf报告程序,它将有三个输入:报告日期、事件日期和事件描述。你知道吗

问题是我创建了一个while循环,以防用户决定添加多个事件,但是PDF总是只显示最后一个事件。有没有人能帮我看看如何把事件添加到PDF中?你知道吗

from fpdf import FPDF

date = input("Type the date (mm/yyy) for your report: ")

while True:

    date_event = input("Type the date of the event (dd/mm/yyy): ")
    event_description = input("Describe the event: ")

    cont = input("To add another event type 1, to generate PDF type 2: ")
    if cont == "2":
        break
    if cont == "1":
        continue


pdf = FPDF()
pdf.add_page()
pdf.set_font("Arial", size=16)
pdf.cell(200, 10, txt="Report for " + date, ln=1, align="C")
pdf.set_line_width(1)
pdf.set_draw_color(255, 150, 150)
pdf.line(20, 20, 195, 20)
pdf.set_font("Arial", size=12)
pdf.multi_cell(0, 15, txt=date_event, align="L")
pdf.multi_cell(0, 8, txt=event_description, align="L")
pdf.output("report.pdf")

我想将event1、event2、event3等等添加到报表中,但是使用这段代码,它只添加了我键入的最后一个事件。你知道吗


Tags: thetxteventinputdatepdf报告事件