[reportlab-users] Platypus Chapters

Tobias Greitzke tobias.greitzke at togis.com
Thu Jun 5 13:28:40 EDT 2014


Hello,

I would like to print the chapter title next to the page number on the 
bottom of the page but I cant figure out how to do that.
I found this post 
(http://two.pairlist.net/pipermail/reportlab-users/2004-March/002821.html) 
but if I try to fill in the doc.chapter it get overwritten by the last 
chapter title in all the other chapters.

this is how the report looks like:
http://fsp.humedica.org/e01/e011/report.pdf?init=5&do=print&opener=FAM10&rs=0&rs=0&rs=1435&rs=1436&rs=1437&rtype=1&cinfo=1

Here is what I got so far:

--- snip ---

def myFirstPage(canvas, doc):

     canvas.saveState()

     myHead(canvas, doc)
     myAddress(canvas, doc)

     canvas.setFont('Open Sans', 9)
     canvas.drawRightString(PAGE_WIDTH - 100,594,"Kaufbeuren, "+datum)

     mySidebar(canvas, doc)

     canvas.restoreState()


def myLaterPages(canvas, doc):

     canvas.saveState()

     myHead(canvas, doc)

     canvas.setFont('Open Sans', 9)
     canvas.drawString(50, 0.75 * inch,"Seite %d / %s" % (doc.page, 
doc.chapter))

     canvas.restoreState()


def makeReport(chapter):

     Story.append(NextPageTemplate('myFirstPage'))
     ---snip---
     Story.append(NextPageTemplate('myFirstPage'))
     Story.append(PageBreak())


def go(chapters):

     buf = StringIO()
     doc = BaseDocTemplate(buf, rightMargin=50, leftMargin=50, 
topMargin=100, bottomMargin=100, author='humedica e.V.')

     global Story
     Story = []

     for chapter in chapters:
        if int(chapter) != 0:
           doc.chapter = chapter
           makeReport(chapter)

     doc.addPageTemplates([
        PageTemplate(id='myFirstPage', onPage=myFirstPage),
        PageTemplate(id='myLaterPages', onPage=myLaterPages)
     ])

     doc.build(Story)

     buf.reset()
     pdfData = buf.read()

     return pdfData


Thanks for your help
Tobias



-- 
tog.is - information design

Tobias Greitzke
Johannes-Mynsinger-Weg 18
89075 Ulm

Fon: +49 (0)731 / 509 4567
Fax: +49 (0)731 / 509 4568
Mobil: +49 (0)163 / 632 32 60
Skype: tobias.greitzke

http://www.togis.com
tobias.greitzke at togis.com



More information about the reportlab-users mailing list