[reportlab-users] page x of y using DocTemplate

Andy Robinson reportlab-users@reportlab.com
Sat, 11 May 2002 00:01:08 +0100

> OK.  This ended up being much easier than I thought it would be.  Here
> is some sample code for anybody else who is wondering how to do this.
> Just append this to your story before doc.build() and it works like a
> charm.

Thanks!  This makes me think - maybe such a class belongs
in the library.  Likewise, one to do the current page
and associate it with some 'id'.

There is a 'lazy' way to do tables of contents in a single 
pass which depends on things like this. It makes certain 
assumptions, like that your page number does not have
so many digits that it stretches off the page :-) But
most indexing and table problems can be solved this
way at the risk of very slight typographic ugliness.

The 'complete' way involves multi-pass rendering and
always gets things right, but at a cost of 2 or 3 
complete passes.  

We could support both in two different subclasses of
DocTemplate.  This has got me thinking that the 'lazy'
route could be made very easy, while we scratch our
headfs abnout the long term one.  We need to add some
'declarative' attributes to paragraphs and other attributes
saying 'I am a destination with this id and this text'.
The quick-and-dirty IndexingDocTemplate hunts them down
and makes forms for each as you have suggested, containing
some text - either the page number or some short bit
of text.  Then, indexes and tables can refer to these
forms by id, and maybe look up some info about their
widths if needed.  We would get full speed generation
with very flexible indexing.  

The only thing which we are really missing now is
intra-sentence links.  Imagine this:
"If you look at paragraph xxx on page [yyy], Guido says"

[yyy] is the page number to be worked out.  Some assumption
must be made about the number of digits and thus the width
so you can format the paragraph, especially since yyy is
not necessarily known until later.  But I guess authors
can often guess if they need 2, 3 or 4 digits and so
the worst case is one extra characters' space.

Damn....too interesting.....must get back to work.....
Definitely a good holiday project!

- Andy