[Python] What is the simplest way to add a hyperlink to a canvas element in ReportLab?

Discussão em 'Python' iniciado por Stack, Maio 24, 2025.

  1. Stack

    Stack Membro Participativo

    I am using ReportLab to make a pdf using Python. I want to add a shape to the canvas, and have that shape act as a hyperlink. What is the simplest way to make the rectangle in the following example link to google.com?

    from reportlab.pdfgen import canvas
    from reportlab.lib.units import inch

    c = canvas.Canvas("hello.pdf")

    # move the origin up and to the left, draw square
    c.translate(inch,9*inch)
    # How do I make this rectangle link to google.com?
    c.rect(inch,inch,1*inch,1*inch, fill=1)

    c.showPage()
    c.save()

    Continue reading...

Compartilhe esta Página