[reportlab-users] Trying to implement "See page X"

Roberto Alsina ralsina at netmanagers.com.ar
Thu Jun 4 08:13:03 EDT 2009


On Thursday 04 June 2009 06:15:07 Robin Becker wrote:

> Roberto Alsina wrote:

> > And it's almost there, but I am doing something wrong :-)

> >

> > Here's my approach: In some cases, instead of a regular paragraph, create

> > a DelayedParagraph wrapper around Paragraph, which is an IndexingFlowable

> > and gets notified of bookmarks.

> >

> > Then, in DelayedParagraph.notify, "fix" the text by replacing references

> > to bookmarks with the corresponding page numbers.

> >

> > Example:

> >

> > 'Go see A title (Page %(a-title)s)'%{'a-title': 2}

> >

> > And it works like a charm... unless the bookmark is *after* the

> > DelayedParagraph, in which case it just gets drawn before the text is

> > "fixed".

> >

> > I though that by returning False to isSatisfied(), the delayedParagraph

> > would not get drawn, then force another build pass, fix the references,

> > then draw it, but I am obviously mistaking.

> >

> > I can't use onDraw like the table of contents does because I need to put

> > the page number in the paragraph textflow, and that means I can't just

> > "save the space" for it.

> >

> > Sadly since this is in rst2pdf extracting a small example is not trivial,

> > I hope my description is useful...

> >

> > Here is my DelayedParagraph class:

> >

> > http://pastebin.com/f60b5f7e9

>

> In general there's no obvious way to do both forward and backward links

> single pass

>

> However, it should be possible to do this with multi-pass without any delay

> at all. What's required is that the variables that are being referenced in

> the draw method have stabilized. Are you using multibuild?


Yes.

However the first "see page X" that is before the definition of the bookmark
gets its draw() called in the first pass, even though it's marked as not
satisfied.

--
("\''/").__..-''"`-. . Roberto Alsina
`9_ 9 ) `-. ( ).`-._.`) KDE Developer (MFCH)
(_Y_.)' ._ ) `._`. " -.-' http://lateral.netmanagers.com.ar
_..`-'_..-_/ /-'_.' The 6,855th most popular site of Slovenia
(l)-'' ((i).' ((!.' according to alexa.com (27/5/2007)
"Our opponent is an alien starship packed with atomic bombs, I said.
We have a protractor. Okay, I’ll go home and see if I can scrounge up a
ruler and a piece of string." — Neal Stephenson


More information about the reportlab-users mailing list