[reportlab-users] Reverse order of pages
Tim Roberts
timr at probo.com
Wed Jun 28 12:39:39 EDT 2006
On Wed, 28 Jun 2006 16:21:18 +0100 (BST), John Smith
<jsmith030416 at yahoo.co.uk> wrote:
>Ideally though, because I am producing this brochure
>on a server, it would be a real convenience to be able
>to reverse the page order whilst staying within
>reportlab.
>
>
Your server can probably use os.system or the subprocess module to call
this so that your clients never know. However, I appreciate the desire
for "purity".
>Am I right in thinking that somewhere in the bowels of
>reportlab there is some routine that works on a list
>of pages to convert the data to a pdf stream? If there
>is, I could find that list, reverse it, and let
>reportlab do its stuff from that point on.
>
Not really, no. For the most part, a page boundary doesn't really mean
very much to Reportlab. The "bowels of reportlab" essentially work with
a stream of PostScript instructions. showPage() flushes pending data
and adds a few PostScript commands to eject the page. There is no
"tree" of data with pages as branches that you can rearrange.
Are you using Platypus to flow this data? If not, then the easiest
solution is to rearrange your own code. When I'm writing
Reportlab-based reports, I often find that I end up with an architecture
like this:
def renderReport( self, ... ):
self.renderCoverPage( self, 0, 0, width, height )
self.canvas.showPage()
self.renderSecondPage( self, 0, 0, width, height )
self.canvas.showPage()
def renderCoverPage( self, left, top, width, height ):
y = self.renderTopTitleBlock( self, left, top, width )
y = self.renderDateBlock( self, left, y, width )
y = self.renderAttributions( self, left, y, width )
etc.
With that kind of architecture, reordering the pages is just a matter of
changing the order of calls in one function. That isn't quite so easy
if you are using Platypus flowables, of course.
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the reportlab-users
mailing list