[reportlab-users] How to pin a flowable/summary chunk at the bottom of a page?

Robin Becker robin at reportlab.com
Tue May 3 12:48:32 EDT 2005


Eric Hochmeister wrote:
> Hi Robin,
> 
> 
>>The final pinned flowable is the key. There are a some special cases.
>>Suppose there is room for the text part of the pin in the current frame then
>>just ensure it uses all the space and draws itself at the right place. If there
>>is not room for the text then presumably you use up all the space on and then
>>you're back in the first case.
> 
> 
> So use a custom flowable then... ?  Does a flowable know how much
> space it needs before its drawn or do I just have to know the size of
> the text contained in the custom pinned flowable?  Just trying to wrap
> my head around how to figure out how to determine how much space the
> flowable needs to use up to get itself to the bottom and still leave
> enough room to contain the summary contents.
> 
> Thanks,
> 
> Eric
> 
..... effectively the wrap method will be called with the available space.
The wrap method needs to determine the height of the summary anyhow.
If we base the summary on a Paragraph the following might be a start;
it is completely untested and will be sensitive to spaceBefore/After.

######
from reportlab.platypus.paragraph import Paragraph
from reportlab.platypus.doctemplate import LayoutError

class PinFlowable(Paragraph):
	def __init__(self,*args,**kw):
		Paragraph.__init__(*((self,)+args),**kw)
		self._wrapped = 0

	def wrap(self, availWidth, availHeight):
		w, h = Paragraph.wrap(self,availWidth,availHeight)
		if h>availHeight:
			if self._wrapped:
				raise LayoutError('PinFlowable not making any progress')
			self._wrapped = 1
			return w, h
		self._extraSpace = availHeight - h
		return w, availHeight

	def split(self,availWidth,availHeight):
		return []

	def drawOn(self, canvas, x, y, _sW=0):
		Paragraph.drawOn(self,canvas,x,y+self._extraSpace,_sw)
######

-- 
Robin Becker


More information about the reportlab-users mailing list