Разрыв страницы ReportLab в python
У меня есть представление для создания из фрейма данных Pandas, которое затем превращает его в PDF файл и возвращает ответ файла. Все работает хорошо, за исключением (см. код ниже для комментария:)
@login_required()
def download_pdf(request, location_name):
current = CurrentInfo()
pdf_data = current.detail_employees_by_location(location_name) # this gives me the list of people
buf = io.BytesIO()
canv = canvas.Canvas(buf, pagesize=letter, bottomup=0)
textob = canv.beginText()
textob.setTextOrigin(inch, inch)
textob.setFont("Helvetica", 10)
pf = pd.DataFrame.from_dict(pdf_data, orient='index', columns=['EmployeeNumber', 'LastFirst'])
data = pf.drop_duplicates()
count = data.count()
data = data.to_records()
line_break = "|"+"-"*150+"|"
textob.textLine(f"Employees in: {location_name} total in site: {count['EmployeeNumber']}")
textob.textLine(line_break)
textob.textLine("{0:^10}{1:^30} {2:^50}".format("#", "Employees Number", "Name"))
textob.textLine(line_break)
for index, line in enumerate(data, start=1):
textob.textLine(f"{index:^10}{line['EmployeeNumber']:^30} {line['LastFirst']:^50}")
textob.textLine(line_break) #when i add this space after each line it causes the page
#to never break and just stay on the resulting in lines
#not showing
canv.drawText(textob)
canv.showPage()
canv.save()
buf.seek(0)
return FileResponse(buf, as_attachment=True, filename='employees.pdf')
Когда я добавляю дополнительный пробел после каждой строки в цикле for для дополнительного интервала, это приводит к тому, что страницы не разрываются и возвращается PDF с плохим форматированием.