在ReportLab中向canvas元素添加超链接的最简单的方法是什么? [英] What is the simplest way to add a hyperlink to a canvas element in ReportLab?

查看:131
本文介绍了在ReportLab中向canvas元素添加超链接的最简单的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ReportLab使用Python制作pdf。我想要添加一个形状到画布上,并使该形状作为一个超链接。以下示例中的矩形是如何链接到google.com的最简单的方法是什么?

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

c = canvas.Canvas(hello.pdf)

#向上和向左移动原点,
c.translate(inch,9 * inch)
#如何将此矩形链接到google.com?
c.rect(inch,inch,1 * inch,1 * inch,fill = 1)

c.showPage()
c.save

解决方案

调用 linkURL

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

矩形是可点击区域,



查看此博客中的更多示例:http://www.hoboes.com/Mimsy/hacks/adding-links-to-pdf/


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()

解决方案

Call linkURL on the Canvas:

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

The rectangle is the clickable area, so you'd have to match that to the drawn rectangle.

See more examples in this blog post: http://www.hoboes.com/Mimsy/hacks/adding-links-to-pdf/

这篇关于在ReportLab中向canvas元素添加超链接的最简单的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆