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

Lele Gaifax lele at metapensiero.it
Sat Dec 19 03:09:11 EST 2020


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:

  story = [....]
  fits = False
  while not fits:
    flowable = SomeFlowable(story)
    if frame.add(flowable, canvas):
      break
    story = replace_some_trailing_text_with_ellipsis(story)

I suspect that a slightly better way could use the split() method on the
flowable, maybe passing it the height of the frame corrected to leave space
for the hyperlink.... I will try to understand the logic used for example by
PTOContainer().

Any hint would be appreciated!

Thanks in advance and best wishes,
ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele at metapensiero.it  |                 -- Fortunato Depero, 1929.



More information about the reportlab-users mailing list