[reportlab-users] mixing flowables and exact placement in
a platypus doc
Andy Robinson
andy at reportlab.com
Mon Mar 6 05:06:39 EST 2006
will at phototropia.org wrote:
> Friends:
> If I have a platypus doc with flowables(paragraphs,tables etc), and I
> want to mix in pages with exact placement drawings,text etc where no
> flowables with the wrap property, I see two ways to do it:
> 1)Define a page template with all of my exact placement
> stuff(text,drawings) without frames, and change to that page template when
> I want to use it, and then change back to a page template with frames for
> flowables.
> 2)Think of a frame as kind of bounding box. Use drawings and text as
> flowables as recommended in the userguide, but calculate the size,
> position and padding of the frame so that the flowed drawing/object ends
> up exactly on the page where you would have placed it by just stating x,y
> coordinates.
>
> I am leaning towards 1, but am I missing something here?
Possibly missing some documentation we should have written ;-)
In Report Markup Language we 'switch modes' all the time, but there are
high level tags to make it obvious. Here's some of the underlying
techniques:
(1)If you're in flowing mode, and you want a rectangular box to draw on,
you can create a special flowable and put your drawing code in it, just
implementing the draw method below. Your graphics will appear relative
to the current rendering position (i.e. between the paragraph above and
below).
class Illustration(Flowable):
def __init__(self, width, height):
self.width = width
self.height = height
def wrap(self, *args):
return (self.width, self.height)
def draw(self):
#my graphics code here....
You are also free to lie about the size and 'draw outside the box', eg.
to make hanging side headings in the margin.
(2) Drawings (the chart classes in reportlab/graphics) work like this too
(3) There are lots of events in BaseDocTemplate for you to override
which can let you draw explicitly when you start/finish a page, a frame
and so on. These would let you draw in absolute page coordinates
(4) when drawing directly, you can easily instantiate any flowable
object and call
thing.drawOn(canvas, x, y),
provided you call
thing.wrap(height, width)
first to tell it the available size. If it's a fixed size just pass the
any old size to wrap(...).
(5) when drawing directly, you can also create a Frame object and add
flowable objects to it. I'd do this if I was rendering some
lines-and-boxes thing like an invoice where I am highly likely to be in
charge of the page breaks, but wanted a few paragraphs of text for the
small print.
I hope this gives you a few ideas. If not, a concrete example of what
you're trying to render would be helpful and I can suggest more specific
strategies.
Good luck,
Andy
More information about the reportlab-users
mailing list