ReportLab 绘制 页面为不同框架 PDF
https://docs.reportlab.com/reportlab/userguide/ch5_platypus/#frame-user-methods
frame0 = Frame(doc.leftMargin, doc.bottomMargin, doc.width /3 - 6, doc.height - doc.bottomMargin, id='col0') frame1 = Frame(doc.leftMargin + doc.width / 3 + 12, doc.bottomMargin, doc.width / 15 - 6, doc.height - doc.bottomMargin, id='col1')#, showBoundary=1 frame2=Frame(doc.leftMargin+ doc.width*(5+1) / 15 + 6, doc.bottomMargin, doc.width *2/ 3 - 6, doc.height - doc.bottomMargin, id='col2') if emplace_num<=5: content.append(Table(data_rtable[:-1],table_cell,repeatRows=(0,1,),style=table_style)) content.append(Spacer(width=doc.width, height=10 * mm)) content.append(Paragraph(f'{datetime.datetime.now().strftime("%Y年%m月%d日")}\0\0\0\0',style_estr)) Page_one_templates=PageTemplate(id='ThreeCol', frames=[frame0,frame1, frame2]) doc.addPageTemplates([Page_one_templates]) else:#分配人数大于5,分2页处理 # frame3 = Frame(doc.leftMargin, doc.bottomMargin, doc.width /3 - 6, doc.height - doc.bottomMargin, id='col0') frame3 = Frame(doc.leftMargin-13, doc.bottomMargin, doc.width *2/ 3 -6, doc.height - doc.bottomMargin, id='col3') frame4=Frame(doc.leftMargin+doc.width*3/4 - 19 , doc.bottomMargin, doc.width /3 - 6, doc.height - doc.bottomMargin, id='col4') Page_one_templates=PageTemplate(id='page_1', frames=[frame0,frame1, frame2]) Page_two_templates=PageTemplate(id='page_2', frames=[frame3, frame4]) doc.addPageTemplates([Page_one_templates,Page_two_templates]) content.append(Table(data_rtable[0:7],table_cell,repeatRows=(0,1,),style=table_style)) content.append(Paragraph(f'————其余{emplace_num-5}人转页背————',style_estr)) content.append(FrameBreak()) doc.handle_nextPageTemplate('page_2')#改变为不同框架页面 content.append(Table(data_rtable[0:2]+data_rtable[7:-1],table_cell,repeatRows=(0,1,),style=table_style)) content.append(Paragraph(f'{datetime.datetime.now().strftime("%Y年%m月%d日")}\0\0\0\0',style_estr)) content.append(FrameBreak()) content.append(Table(data_ltable[0:2]+data_ltable[7:-1],table_cell,repeatRows=(0,1,),style=table_style)) doc.build(content)
浙公网安备 33010602011771号