2015-11-03 2 views
0

Я хочу два PageTemplates на одной странице. т.е. сначала я хочу обычный кадр с одним столбцом, тогда я хочу, чтобы остальная часть страницы имела два столбца. Но всякий раз, когда я использую FrameBreak(), он переходит к следующей странице. Почему это так?Reportlab: 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/>[email protected]</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 поэтому, пожалуйста, простите меня за какие-либо очевидные ошибки ...

ответ

1

Я хочу два PageTemplates в одном страница

Как следует из названия, PageTemplate шаблон для страницы - так что вы не можете очевидно, есть две на одной странице. То, что вы хотите, это один шаблон страницы с тремя кадрами.

+0

Oh ... Итак, первый кадр должен иметь ширину документа, следующий кадр должен быть первым столбцом, а третий - вторым столбцом справа? – memnonila

+0

@memnonila да точно. –

 Смежные вопросы

  • Нет связанных вопросов^_^