[reportlab-users] Dynamic page sizes
robin at reportlab.com
Fri Oct 21 04:57:33 EDT 2011
On 21/10/2011 00:53, Glenn Linderman wrote:
> On 10/19/2011 1:45 AM, Robin Becker wrote:
> OK, this sounds like a reasonable prospect. Let's see if I grasp the concept:
> 1. create an empty list of templates for each page
> 2. process each item (poem), creating a flowable, and use the wrap method,
> pretending that it has an 8.5x11 page when calling it, and discovering the
> actual size. At that point, append a template that has a page of that size to
OK there is an issue here in that paragraphs will always occupy the full width
of the space they're given. You can get round this (approximately at least) by
assuming that the total area occupied by the paragraph is constant. Of course if
you intend always to have a page width of 8.5 (minus indents and decorations
etc) then you're home already. generally unless you force otherwise frames have
automatic margins of 6 points so take that into account as well.
> the template list, and append the flowable to the set of flowables.
> 3. create a document, using the list of templates, and the list of flowables
> 4. build the document
> Questions that come to mind,
> A. is the flowable still reusable for the document after doing the
> pre-processing wrap method? I guess the worst case is that I discard it and
> create a new one without calling wrap on it.
It should be.
> B. margins: I'm not clear on whether the wrap size includes the margins or not,
> I would guess not, but it seems that with a 3-column layout I did for something
> else, that each frame may have had a bit of margin, even though I tried to
> specify none. But that layout was using tables inside the frames, so maybe there
> was interaction with that as well.
The template contains a frame whose size if fixed by the construction. Frames
have padding in general of 6 points (top and bottom left/right). When the
doctemplate processes a flowable it will use the frames add method and that
takes the padding current position spaceBefore/After etc etc into account to
poisiton the flowable in the frame or to reject and ask for a split etc etc.
The frame's size and padding can be controlled explicitly, (not in the simple
doc template though unless you get creative and override the build method).
> Anyway, I suspect I can get something working with a bit of experimentation.
> I'll look into the document object APIs a bit more for page number info, etc.
More information about the reportlab-users