在ReportLab中向canvas元素添加超链接的最简单方法是什么?

jap*_*hyr 5 python canvas reportlab hyperlink

我正在使用ReportLab使用Python制作pdf.我想在画布上添加一个形状,并将该形状作为超链接.在以下示例中将矩形设为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()
Run Code Online (Sandbox Code Playgroud)

Mar*_*ers 11

呼吁linkURL画布:

c.linkURL('http://google.com', (inch, inch, 2*inch, 2*inch), relative=1)
Run Code Online (Sandbox Code Playgroud)

矩形是可点击区域,因此您必须将其与绘制的矩形相匹配.参数是两个坐标,x, y左下角和右上角两次.

请参阅此博客文章中的更多示例:http://www.hoboes.com/Mimsy/hacks/adding-links-to-pdf/