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

标签 python canvas hyperlink reportlab

我正在使用 ReportLab 使用 Python 制作 pdf。我想在 Canvas 上添加一个形状,并将该形状用作超链接。在以下指向 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()

最佳答案

在 Canvas 上调用 linkURL:

c.linkURL('http://google.com', (inch, inch, 2*inch, 2*inch), relative=1)

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

在这篇博文中查看更多示例:http://www.hoboes.com/Mimsy/hacks/adding-links-to-pdf/

关于python - 在 ReportLab 中向 Canvas 元素添加超链接的最简单方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10688923/

相关文章:

javascript - Canvas 与 SVG 之声波图像交互

Facebook 检查页面是否为用户 "Liked"

javascript - 如何将 fillPatternImage 置于楔形中心?

HTML:如何正确设置超链接列表的样式

python - 删除继承类Python中的类属性

python - 通过树莓派同时播放多个声音文件,最好使用python

python - 你能澄清一下Python中的这个引用问题吗?

PHP/MySQL 表动态链接

html - 查询字符串中 Base64 编码参数的问题

python - TypeError ("' NoneType'对象没有属性 '__getitem__'“,)