Reportlab:FrameBreak() 创建一个新页面?
Reportlab: FrameBreak() creating a new page?
我想在一个页面中使用两个页面模板。即,起初我想要一个只有一列的普通框架,然后我希望页面的其余部分有两列。但每当我使用 FrameBreak() 时,它都会转到下一页。为什么会这样?
这是整个pdf生成代码...
def pdf_gen():
styles = getSampleStyleSheet()
styles.add(ParagraphStyle(name='justify', alignment=TA_JUSTIFY))
styles.add(ParagraphStyle(name='center', alignment=TA_CENTER))
styles.add(ParagraphStyle(name='right', alignment=TA_RIGHT))
doc = BaseDocTemplate("services.pdf", pagesize=A4,
rightMargin=72, leftMargin=72,
topMargin=12, bottomMargin=18)
#normal frame as for SimpleFlowDocument
frameT = Frame(doc.leftMargin, doc.bottomMargin, doc.width, doc.height, id='normal')
#Two Columns
frame1 = Frame(doc.leftMargin, doc.bottomMargin, doc.width/2-6, doc.height, id='col1')
frame2 = Frame(doc.leftMargin+doc.width/2+6, doc.bottomMargin, doc.width/2-6, doc.height, id='col2')
doc.addPageTemplates([PageTemplate(id='OneCol',frames=frameT),
PageTemplate(id='TwoCol',frames=[frame1, frame2]),
])
Story = []
logo = "total_startup_club_logo_on_white_background.png"
formatted_time = time.ctime()
im = Image(logo, 1*inch, 1*inch)
ptext1 = '<font size=16><strong>PROJECT XXXXX</strong></font>'
ptext2 = '<font size=8>Level 39, Marina Bay Financial Centre,<br/> Tower 2, 10 Marina Boulevard, Singapore,<br/>018983,Phone: +65 6818 6289 <br/>hello@totalreturn.club</font>'
data = [[im, Paragraph(ptext1, styles["center"]), Paragraph(ptext2, styles["right"])]]
t = Table(data, 2.2*inch)
Story.append(t)
Story.append(Spacer(1, 12))
#ptext = '<font size=16><strong>Service Request</strong></font>'
#Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 12))
ptext = '<font size=12>%s</font>' % formatted_time
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 12))
Story.append(NextPageTemplate('TwoCol'))
Story.append(FrameBreak())
#Story.append(PageBreak())
ptext = '<font size=12>TRANSACTION SUMMARY</font>'
Story.append(Paragraph(ptext, styles["justify"]))
Story.append(Spacer(1, 12))
services = [
'this is sparta',
'how is this possible',
]
#Story.append(NextPageTemplate('TwoCol'))
ptext = '<font size=12>TRANSACTION SUMMARY</font>'
Story.append(Paragraph(ptext, styles["justify"]))
Story.append(Spacer(1, 12))
for service in services:
ptext = '<font size=10> - <em>%s</em></font>' % service
Story.append(Paragraph(ptext, styles["justify"]))
Story.append(Spacer(1, 12))
Story.append(Paragraph("Frame two columns, "*500,styles['Normal']))
#builds the pdf
doc.build(Story)
if __name__ == '__main__':
pdf_gen()
我是 reportlab 的新手,所以请原谅我任何明显的错误...
I want two PageTemplates in a single page
顾名思义,一个 PageTemplate
一个 页面的模板 - 所以显然你不能在同一页面上有两个。您想要的是具有三个框架的单个 PageTemplate。
我想在一个页面中使用两个页面模板。即,起初我想要一个只有一列的普通框架,然后我希望页面的其余部分有两列。但每当我使用 FrameBreak() 时,它都会转到下一页。为什么会这样?
这是整个pdf生成代码...
def pdf_gen():
styles = getSampleStyleSheet()
styles.add(ParagraphStyle(name='justify', alignment=TA_JUSTIFY))
styles.add(ParagraphStyle(name='center', alignment=TA_CENTER))
styles.add(ParagraphStyle(name='right', alignment=TA_RIGHT))
doc = BaseDocTemplate("services.pdf", pagesize=A4,
rightMargin=72, leftMargin=72,
topMargin=12, bottomMargin=18)
#normal frame as for SimpleFlowDocument
frameT = Frame(doc.leftMargin, doc.bottomMargin, doc.width, doc.height, id='normal')
#Two Columns
frame1 = Frame(doc.leftMargin, doc.bottomMargin, doc.width/2-6, doc.height, id='col1')
frame2 = Frame(doc.leftMargin+doc.width/2+6, doc.bottomMargin, doc.width/2-6, doc.height, id='col2')
doc.addPageTemplates([PageTemplate(id='OneCol',frames=frameT),
PageTemplate(id='TwoCol',frames=[frame1, frame2]),
])
Story = []
logo = "total_startup_club_logo_on_white_background.png"
formatted_time = time.ctime()
im = Image(logo, 1*inch, 1*inch)
ptext1 = '<font size=16><strong>PROJECT XXXXX</strong></font>'
ptext2 = '<font size=8>Level 39, Marina Bay Financial Centre,<br/> Tower 2, 10 Marina Boulevard, Singapore,<br/>018983,Phone: +65 6818 6289 <br/>hello@totalreturn.club</font>'
data = [[im, Paragraph(ptext1, styles["center"]), Paragraph(ptext2, styles["right"])]]
t = Table(data, 2.2*inch)
Story.append(t)
Story.append(Spacer(1, 12))
#ptext = '<font size=16><strong>Service Request</strong></font>'
#Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 12))
ptext = '<font size=12>%s</font>' % formatted_time
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 12))
Story.append(NextPageTemplate('TwoCol'))
Story.append(FrameBreak())
#Story.append(PageBreak())
ptext = '<font size=12>TRANSACTION SUMMARY</font>'
Story.append(Paragraph(ptext, styles["justify"]))
Story.append(Spacer(1, 12))
services = [
'this is sparta',
'how is this possible',
]
#Story.append(NextPageTemplate('TwoCol'))
ptext = '<font size=12>TRANSACTION SUMMARY</font>'
Story.append(Paragraph(ptext, styles["justify"]))
Story.append(Spacer(1, 12))
for service in services:
ptext = '<font size=10> - <em>%s</em></font>' % service
Story.append(Paragraph(ptext, styles["justify"]))
Story.append(Spacer(1, 12))
Story.append(Paragraph("Frame two columns, "*500,styles['Normal']))
#builds the pdf
doc.build(Story)
if __name__ == '__main__':
pdf_gen()
我是 reportlab 的新手,所以请原谅我任何明显的错误...
I want two PageTemplates in a single page
顾名思义,一个 PageTemplate
一个 页面的模板 - 所以显然你不能在同一页面上有两个。您想要的是具有三个框架的单个 PageTemplate。