[reportlab-users] Bookmarking & Zoom (+BugFix)

Ian Sparks reportlab-users@reportlab.com
Thu, 6 Feb 2003 11:23:54 -0500


Well, I took Andy's advice and read the necessary parts of the PDF Spec =
and the ReportLab source code.

Recap : The problem I was trying to solve is that a client complained =
that if they set the zoom to 125% and then clicked an internal link, the =
resulting page was set to /Fit and their 125% zoom was lost.

This is covered at the bottom of page 184 of the PDF Spec and the key =
setting is :

/XYZ left top zoom=20

0 or 'null' for any of these values means "maintain values from page you =
were on"

ReportLab uses :

 /Fit for canvas.bookmarkPage=20
 /FitH for canvas.bookmarkHorizontalAbsolute=20

changing these to :

def bookmarkPage(self, key):
...code...
#        dest.fit() #old=20
        dest.xyz(0,0,0) #new
...code...

and=20

def bookmarkHorizontalAbsolute(self, key, yhorizontal):
...code...
#        dest.fith(yhorizontal) #old
        dest.xyz(1,yhorizontal,0)=20
#note left=3D1 above because 0 means no change and you could get left =
hanging out on the page
...code...

solves my problem *if* I first fix the bug in pdfdoc.py :

class PDFDestinationXYZ:
    typename =3D "XYZ"
    def __init__(self, page, left, top, zoom):
        self.page =3D page; self.top=3Dtop; self.zoom=3Dzoom
-->        self.left =3D left; #lets not forget left!!!
    def format(self, document):
        pageref =3D document.Reference(self.page)
        A =3D PDFArray( [ pageref, PDFName(self.typename), self.left, =
self.top, self.zoom ] )
        return format(A, document)

Adding some support to canvas.bookmarkPage and =
canvas.bookmarkHorizontalAbsolute to allow zoom,x position or the type =
of Fit setting (perhaps by passing in an optional PDFDestinationFit =
object?) should just be a matter of typing.

Andy, would you consider adding this support?

- Ian Sparks.