Frage

I know that I can internally link with canvas, but my whole doc's set up with Platypus. Does Platypus support internal linking? How hard is migrating to canvas if it doesn't?

Thanks in advance!

War es hilfreich?

Lösung

You can use intra-paragraph markup to create anchors (<a> tag) and links (<link> tag), as explained in the section 6.3 Intra-paragraph markup (chapter 6, page 72) of the ReportLab 2.6 User Manual PDF, which also contains the following example:

This <a href="#MYANCHOR" color="blue">is a link to</a> an
anchor tag ie <a name="MYANCHOR"/><font color="green">here</font>.
This <link href="#MYANCHOR" color="blue" fontName="Helvetica">is
another link to</link> the same anchor tag.

Andere Tipps

An approach inspired by https://www.blog.pythonlibrary.org/2014/03/10/reportlab-how-to-create-custom-flowables/.

Create a custom class inherited from Flowables, which can be added to the "story"

class flowable_bookmark(Flowable):
    def __init__(self, x=0, y=0, width=10, height=10, bookmark_name = "", text=""):
        Flowable.__init__(self)
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self.bookmark_name = bookmark_name
        self.text = text

    def draw(self):
        self.canv.drawString(self.x, self.y, self.text)
        self.canv.bookmarkPage(self.bookmark_name)

Usage:

my_anchor = flowable_bookmark("MYANCHOR", text=" ")
self.story.append(my_anchor)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top