[reportlab-users] RE: Creating outlines and bookmarks from Platypus?

Marc Stober reportlab-users@reportlab.com
Mon, 22 Mar 2004 09:04:54 -0500


Hi Dave,

Here's the class I use to create bookmarks. You're probably right that it
should inherit from ActionFlowable and not just Flowable; this has always
worked for me anyhow. It would have to be extended further to support nested
bookmarks.

class Bookmark(Flowable):
    """ Utility class to display PDF bookmark. """

    def __init__(self, title, key):
        self.title = title
        self.key = key
        Flowable.__init__(self)

    def wrap(self, availWidth, availHeight):
        """ Doesn't take up any space. """
        return (0, 0)

    def draw(self):
        # set the bookmark outline to show when the file's opened
        self.canv.showOutline()
        # step 1: put a bookmark on the 
        self.canv.bookmarkPage(self.key)
        # step 2: put an entry in the bookmark outline
        self.canv.addOutlineEntry(self.title,
                self.key, 0, 0)