[reportlab-users] Variant nextPageTemplate's: "chapter" pages with subsequent pages

wandering free walkingreen at googlemail.com
Fri Jan 25 13:29:09 EST 2013


On 24 January 2013 16:43, Robin Becker <robin at reportlab.com> wrote:


> we do have code in the toolkit to allow dynamic behaviours in the story

> see the module reportlab/platypus/flowables.py for

>

> DocAssign, DocExec, DocAssert, DocPara, DocIf & DocWhile

>

> these flowables represent really primitive computational constructs which

> are evaluated at layout time.

>

> sample from the latest tests folder

>

>

> from reportlab.lib.styles import ParagraphStyle

>> from reportlab.platypus import SimpleDocTemplate, Paragraph

>> from reportlab.platypus.flowables import DocAssign, DocExec, DocPara,

>> DocIf, DocWhile

>> normal = ParagraphStyle(name='Normal', fontName='Helvetica',

>> fontSize=8.5, leading=11)

>> header = ParagraphStyle(name='Heading1'**, parent=normal, fontSize=14,

>> leading=19,

>> spaceAfter=6, keepWithNext=1)

>> story = [

>> DocAssign('currentFrame','doc.**frame.id<http://doc.frame.id>

>> '),

>> DocAssign('**currentPageTemplate','doc.**pageTemplate.id<http://doc.pageTemplate.id>

>> '),

>> DocAssign('aW','**availableWidth'),

>> DocAssign('aH','**availableHeight'),

>> DocAssign('aWH','**availableWidth,**availableHeight'),

>> DocAssign('i',3),

>> DocIf('i>3',Paragraph('The value of i is larger than

>> 3',normal),Paragraph('The value of i is not larger than 3',normal)),

>> DocIf('i==3',Paragraph('The value of i is equal to

>> 3',normal),Paragraph('The value of i is not equal to 3',normal)),

>> DocIf('i<3',Paragraph('The value of i is less than

>> 3',normal),Paragraph('The value of i is not less than 3',normal)),

>> DocWhile('i',[DocPara('i',**format='The value of i is

>> %(__expr__)d',style=normal),**DocExec('i-=1')]),

>> DocPara('repr(doc._nameSpace)'**,escape=True),

>> DocPara('doc.canv.**getPageNumber()','The current page

>> number is %(__expr__)d',style=normal)

>> ]

>> doc = SimpleDocTemplate(outputfile('**test_doc_programming.pdf'))

>> doc.build(story)

>>

>

> you can access the document doc and lots of its properties etc etc. That

> should allow you to check the page number and then select a suitable

> template using appropriate logic.



Thank you, Robin. I will definitely look into this.
However, I have been offered another solution that I would like to first
explore:
using BaseDocTemplate afterFlowable to track when I am starting a new plant
and check if I´m on an odd or even page;
then using _handle_nextPageTemplate() to append the appropriate template
cycle.
I shall post again with a code snippet should it work out :)
Thanks again; I am certainly glad of your information for future knowledge.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20130125/3887a2bd/attachment.html>


More information about the reportlab-users mailing list