[reportlab-users] Finding if a flowable is at the top of a page.

Roberto Alsina ralsina at netmanagers.com.ar
Mon Apr 19 16:57:53 EDT 2010


I am trying to implement "real" footnotes in rst2pdf, and I thought I had been
so clever... here's my idea:

* Mark the footnote flowables (by setting .isFootnote to True).

* Run a multiBuild

* When doing the multiBuild, mark all flowables that are at the top of frames
somehow.

* Since the total space used on the page doesn't change, I can now rearrange
the footnotes to be right before the next "top of frame" flowable.

That makes them *always* be the last flowable in the frame.

* Then, I replace them with a custom "Sinker" flowable that takes all
available verical space in a frame and draws the content at the bottom.

* One final build, and voila, real footnotes.

The only part that is not reliable is... finding out if a flowable is at the
top of a frame.

I did it like this first, replacing my frames' add method:

def add (self, flowable, canv, trySplit=0):
flowable._atTop=self._atTop
return Frame.add(self, flowable, canv, trySplit)


And that works **almost** every time, but it doesn't if a flowable doesn't
fit, splits, and the **second** piece is at the top of the frame.

I must confess I just spent the last 4 hours reading
BaseDocTemplate.handle_flowable and my eyeballs are bleeding :-(

Any hints?


More information about the reportlab-users mailing list