ReportLab:为什么两列输出将恢复到单列



我想在ReportLab中生成两列页面。附件程序(根据各种示例进行了改编(生成两个带有两个列的页面,然后生成单列页面。

我尝试创建首先和后续页面的多个页面模板。这不会改变输出。

from reportlab.platypus import SimpleDocTemplate, Frame, Paragraph
from reportlab.platypus import Spacer, PageTemplate, NextPageTemplate
from reportlab.lib.styles import getSampleStyleSheet
styles = getSampleStyleSheet()
doc = SimpleDocTemplate ("try.pdf")
style = styles["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='TwoCol', frames=[frame1,frame2]))
Story = []
Story.append (NextPageTemplate(['TwoCol']))
for rec in range (1, 200):
    line = ("<para><b>Paragraph %s:</b> " % rec)
    line += "This is the text of the paragraph. More text of the paragraph."
    line += " Even more text.</para>n"
    p = Paragraph(line, style)
    Story.append(p)
doc.build (Story)

我在" story.append(p("之后添加了以下内容,以查看它是否会解决:

    if rec % 40 == 0: 
        Story.append (NextPageTemplate(['TwoCol']))

现在,第1页&amp;2是两列,第3页是一列,第4页&amp;5是两列。

我看了simperedoctemplate.build((。它创建一个完整的页面框架(id ='first'(,并将其添加到文档的pagetemplates列表中。

它看起来像基于octemplate.build((拾取即将生成的每个页面的下一个pagetemplate。我认为这有时会导致默认值选择。

我用基于octemplate替换了简单的板块。现在,所有页面均使用两列生成。

最新更新