如何使用reportlab添加指向单词的链接? [英] How to add a link to the word using reportlab?

查看:50
本文介绍了如何使用reportlab添加指向单词的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对链接和报告实验室感到困惑.我想要一个带有单词的文本,其中包含"一个可点击的链接.例如,我写了这样的文字:这个网站叫做 StackOverflow. 我希望 StackOverflow 这个词是可点击的,并能引导到相应的页面.

I am confused with the links and reportlab. I would like to have a text with a word, which 'contains' a clickable link. For example, I write such text: This web-site is called StackOverflow. And I want the word StackOverflow to be clickable and to lead to the corresponding page.

有什么办法可以实现吗?

Is there any way to achieve that?

更新

在这种情况下,我想将超链接添加到单词,而不仅仅是画布.

In this case I want to add the hyperlink to the word, not just to the canvas.

推荐答案

非常感谢 Steven Byrne,他提出了 Jerry Stratton 的解决方案 <- 也非常感谢他!

So, super great thanks to Steven Byrne, who suggested the solution by Jerry Stratton <- to whom also super great thanks!

我只是上传这个简单的代码,所以任何需要这样解决方案的人都可以看看:

I am just uploading this simple code, so for anyone who's in need of such a solution to have a look:

from reportlab import platypus
from  reportlab.lib.styles import ParagraphStyle as PS
from reportlab.platypus import SimpleDocTemplate

items = []
address = 'WHATEVERYOUWNATTOTYPE'
address = '<link href="' + 'http://www.hoboes.com/Mimsy/hacks/adding-links-to-pdf/' + '">' + address + '</link>'
items.append(platypus.Paragraph(address, PS('body')))
doc = SimpleDocTemplate('testLInk.pdf')#, pagesize = reportlab.lib.pagesizes.portrait(reportlab.lib.pagesizes.A4))
doc.multiBuild(items)

链接将指向原始解决方案.

This link will lead to the original solution.

这篇关于如何使用reportlab添加指向单词的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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