[reportlab-users] Float flowable to bottom of page

Robin Becker robin at reportlab.com
Thu Feb 4 07:43:51 EST 2010


On 04/02/2010 10:16, Andy Robinson wrote:

> On 3 February 2010 21:59, James Lance<james at thelances.net> wrote:

>> Is there a way to make a flowable element float to the bottom of the page?

>>

>> I'm working on a invoice document, at the bottom of the page is a tear off segment that can be returned with payment. I can draw directly on the canvas, but I don't want to include the segment on every page, just the last.

>>

>> What I've done is put all the elements that make up my tear off segment into a KeepTogether flowable. I've tried messing around with putting a spacer before it what attempts to fill all remaining space with out pushing it to the next page. I can't seem to work out the correct height of the spacer, and still be flexible concerning the previous flowable content. Of course if there are enough line items or other data then naturally the tear off segment will go to the next page.

>>

>> So, how can I pin the tear off to the bottom of the page while still keeping it a flowable? Is that even possible?

>

> We added some new flowables last year for 'position dependent logic'.

> Look at DocIf and DocWhile in reportlab/platypus/flowables.py for the

> code, and tests/test_platypus_programming.py for examples.

>

> You could potentially 'wrap up' a spacer so that it says "While I

> have more then X inches left, output an invisible chunk and move down

> an inch".

>

> Hope this helps

This logic is probably insufficient because there might be less than X inches left.

If we assume that X is known and X will fit on a full page then you should be
able to achieve this with a single extra bit of logic, use up all except X
inches or do a page throw and then use up all except X inches.

How about this

########################################
from reportlab.platypus.flowables import UseUpSpace, PageBreak
class UseUpSpaceX(UseUpSpace):
def __init__(self,requiredHeight):
self._rH = requiredHeight
self._s = False

def wrap(self,aW,aH):
h = aH-self._rH
if h<0: h = aH+1
return aW,h

def split(self,aW,aH):
if self._s: return []
self._s = True
return [PageBreak(),self]

if __name__=='__main__':
from reportlab.platypus.doctemplate import SimpleDocTemplate
from reportlab.platypus.paragraph import Paragraph
from reportlab.platypus.flowables import Spacer, KeepTogether, _listWrapOn
from reportlab.lib.styles import getSampleStyleSheet
ss = getSampleStyleSheet()
Normal= ss['Normal']
d = SimpleDocTemplate('flowfloat0.pdf')
fh = d.height - 12
fw = d.width - 12

t1 = '''Comparing these examples with their parasitic gap counterparts in (96)
and (97), we see that relational information is to be regarded as an
abstract underlying order. We have already seen that a descriptively
adequate grammar is rather different from the extended c-command
discussed in connection with (34). To characterize a linguistic level
L, the natural general principle that will subsume this case raises
serious doubts about the ultimate standard that determines the accuracy
of any proposed grammar. A consequence of the approach just outlined is
that an important property of these three types of EC is not quite
equivalent to the traditional practice of grammarians. A majority of
informed linguistic specialists agree that this selectionally introduced
contextual feature does not readily tolerate a parasitic gap
construction.
'''
t2 ='''However, this assumption is not correct, since the descriptive power of
the base component is not subject to nondistinctness in the sense of
distinctive feature theory. Note that this selectionally introduced
contextual feature is not to be considered in determining a corpus of
utterance tokens upon which conformity has been defined by the paired
utterance test. I suggested that these results would follow from the
assumption that the natural general principle that will subsume this
case is unspecified with respect to the ultimate standard that
determines the accuracy of any proposed grammar. Note that the earlier
discussion of deviance does not affect the structure of nondistinctness
in the sense of distinctive feature theory. A consequence of the
approach just outlined is that the theory of syntactic features
developed earlier is not quite equivalent to the ultimate standard that
determines the accuracy of any proposed grammar.'''

L =[Paragraph(t1,Normal),Paragraph(t2,Normal)]
w,X=_listWrapOn(L,fw,None,None)
print fw, w,X

S =[] #the story

#First create a case where we need the page throw
S.append(Paragraph('Line 1 followed by lots of space',Normal))
S.append(Spacer(10,fh-X+10))
S.append(Paragraph('Line 2',Normal))
S.append(UseUpSpaceX(X))
S.append(KeepTogether([Paragraph(t1,Normal),Paragraph(t2,Normal)]))
d.build(S)

d = SimpleDocTemplate('flowfloat1.pdf')
#First create a case where we need the page throw
S.append(Paragraph('Line 1 followed by less space',Normal))
S.append(Spacer(10,fh-X-100))
S.append(Paragraph('Line 2',Normal))
S.append(UseUpSpaceX(X))
S.append(KeepTogether([Paragraph(t1,Normal),Paragraph(t2,Normal)]))
d.build(S)

--
Robin Becker


More information about the reportlab-users mailing list