[reportlab-users] Conditional Frame/Page Break
b1205
b1205 at cox.net
Wed Nov 17 20:58:28 EST 2004
Hello,
(Please forgive me if this is a duplicate post as I am new to mailing lists.)
I am using the PLATYPUS framework to generate a 3 page document. Each
page contains several frames.
Eventually I would like to use a database query to return a list with
each element populating a frame. For the majority of elements I will be
able to control frame breaks from the database side by limiting the
character length. For example, a date element from the database will
always be X characters and the frame behavior _should_ be controlled by
the frame dimensions. Since I am still doing layout and have not tied
the database query in yet I am using test strings such as:
story.append(Paragraph("John Doe", styleNormal))
story.append(FrameBreak)
story.append(Paragraph("PHB", styleNormal))
story.append(FrameBreak)
story.append(Paragraph("2004-11-16", styleNormal))
story.append(FrameBreak)
where "John Doe" will eventually be replaced by:
for value in result:
story.append(Paragraph(value, styleNormal))
story.append(FrameBreak)
I do have one variable which _may_ be long enough to break the
frame/page.
One page 2 the last frame is (self.pts is an instance of a point class):
fr45 = Frame(self.pts[17].x + X_OFF, self.pts[17].y + Y_OFF,
532, 186, id='long_string')
One page 3 the first frame is:
fr1 = Frame(self.pts[7].x + X_OFF, self.pts[7].y + Y_OFF,
532, 336, id='long_string_1')
For example if long_variable is large enough to spill from fr45->fr1
this will work:
for value in result:
story.append(Paragraph(value, styleNormal))
story.append(FrameBreak) # This will break out of fr1
# and the next element of fixed
# length will populate fr2.
However if long_variable = "Not so long" then:
for value in result:
story.append(Paragraph(value, styleNormal))
story.append(FrameBreak) # This will break out of fr45,
# however the next fixed element
# will populate fr1 versus flowing to fr2
# where it should be.
I thought I could use the DocTemplate class afterFlowable:
def afterFlowable(self, flowable):
#psudeo code
#check to see what flowable we just finished
if flowable.identity() == long_variable: # This won't work as I
can't
# seem to find a way
# to uniquely identify the flowable
# (i.e. The element of the result list)
#If we finished the flowable on page 2
if self.page.id == 2:
#Break out of fr45 and flow to 3rd page, fr1
self.handle_frameEnd()
#The default frame break should force
#the next flowable to page3 fr2
#If we finished the flowable on page 3
elif self.page.id == 3:
#Do nothing as the default frame break should push us to fr2
I thought CondPageBreak may work but I don't think that this will work
either.
Maybe using handle_frameEnd() I could check to see what the current/next
flowable is?
In summary, I guess my question is how can I produce the behavior where:
If the long_variable does _not_ cause a page break -> the next frame
should be fr2 on Page3
If the long_variable does cause a page break continue normally onto the
next frame which is fr2
Thanks in advance,
Brian
More information about the reportlab-users
mailing list