[reportlab-users] Querying left over space

Robin Becker robin at reportlab.com
Mon Sep 14 12:59:45 EDT 2009


Mike Driscoll wrote:

> Hi,

>

> Is there a way to query how much horizontal and vertical space is left

> on a page? And is there a way to know how much "space" a line of text in

> 10 point will take up? I am working with nested tables and it keeps

> splitting one of the nested over two pages whereas I need it to keep the

> nested table in one piece. I hope that makes sense.

>

> I am coding on a Windows XP machine with Python 2.5 and ReportLab 2.3.

>

> Thanks,

>

> Mike

......
I assume that you're using platypus to do the layout; the document's active
template has an active frame that controls the layout. The coding that's used to
determine whether something can be added is in the _add method of the Frame
class. It looks something like this

y = self._y
p = self._y1p
s = 0
aW = self._getAvailableWidth()
if not self._atTop:
s =flowable.getSpaceBefore()
if self._oASpace:
s = max(s-self._prevASpace,0)
h = y - p - s
if h>0:
w, h = flowable.wrap(aW, h)
else:
return 0
h += s
y -= h
if y < p-_FUZZ:
if not rl_config.allowTableBoundsErrors and ((h>self._aH or w>aW) and not
trySplit):
from reportlab.platypus.doctemplate import LayoutError
raise LayoutError("Flowable %s (%sx%s points) too large for frame (%sx%s
points)." % (
flowable.__class__, w,h, aW,self._aH))
return 0
else:
#DRAW THE FLOWABLE AT self._x, y

if you ignore the space before stuff then effectively the vertical space
remaining is
activeFrame._y - activeFrame._y1p

hope this helps.
--
Robin Becker


More information about the reportlab-users mailing list