[reportlab-users] Truncating a flowable to fit a frame

Robin Becker robin at reportlab.com
Sat Dec 19 04:21:37 EST 2020


There's a KeepInFrame class in flowables.py which can truncate

def __init__(self, maxWidth, maxHeight, content=[], mergeSpace=1, mode='shrink',
		name='',hAlign='LEFT',vAlign='BOTTOM', fakeWidth=None):

you set maxWidth maxHeight to match the dimensions of the real frame; mode='truncate'; your flowables go in the content 
list. You could make this into a flowable which lies about it's wrap and leaves enough space for your see here content.

A possible alternative is to mess with the  PTOContainer class and lie about its split. Normally it splits into

A [lead part + trailer] and another PTO. If I read you correctly you would just return an empty second part.

So something like this

class MyTruncator(PTOContainer):
     def split(self, availWidth, availHeight):
         S = PTOContainer.split(self, availWidth, availHeight)
	return [S[0]] if len(S)==2 else S

I'm not sure if that actually works, but the intent is to drop the remainder after splitting.

Merry Christmas to one and all

On 19/12/2020 08:09, Lele Gaifax wrote:
> Hi,
> 
> an app of mine produces a periodic newsletter, mostly composed by a set of
> fixed size frames that are filled with some flowable content. The "editor"
> user has the responsibility of tweaking the content to make it fit in each
> frame.
> 
> Now I'm asked about a different approach, where the content for some of those
> "areas" may be arbitrarily long, and the system automatically truncates each
> flowable as soon as the related frame is full, possibly leaving some space at
> the bottom to add something like 'See <a href="here">full content here</a>'.
> 
> A brute force implementation would be something like:
> 
........
> 
> Thanks in advance and best wishes,
> ciao, lele.
> 


-- 
Robin Becker


More information about the reportlab-users mailing list