I want two PageTemplates in a single page. ie, At first I want a normal frame with a single column then, I want the rest of the page to have two columns. But whenever I use the FrameBreak() it goes to the next page. Why is it that?
This is the whole pdf generating code...
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()
I am new to reportlab so please forgive me for any obvious mistakes...
I want two PageTemplates in a single page
As the name implies, a PageTemplate
a template for a page - so you cannot have two on the same page, obviously. What you want is a single PageTemplate with three frames.