python–ReportLab图片链接

python–ReportLab图片链接,第1张

概述有没有办法在ReportLab中添加一个href / link到Platypus Image对象?我知道如何在段落中添加文本链接,但我似乎无法找到有关为图像添加链接的任何信息.最佳答案这可以通过missmely提出的HyperlinkedImage class轻松实现:from reportlab.platypus import Image class H

有没有办法在ReportLab中添加一个href / link到Platypus Image对象?我知道如何在段落中添加文本链接,但我似乎无法找到有关为图像添加链接的任何信息.最佳答案这可以通过missmely提出的HyperlinkedImage class轻松实现:

from reportlab.platypus import Imageclass HyperlinkedImage(Image,object):    # The only variable I added to __init__() is hyperlink. I default it to None for the if statement I use later.    def __init__(self,filename,hyperlink=None,wIDth=None,height=None,kind='direct',mask='auto',lazy=1):        super(HyperlinkedImage,self).__init__(filename,wIDth,height,kind,mask,lazy)        self.hyperlink = hyperlink    def drawOn(self,canvas,x,y,_sW=0):        if self.hyperlink: # If a hyperlink is given,create a canvas.linkURL()            x1 = self.hAlignAdjust(x,_sW) # This is basically adjusting the x coordinate according to the alignment given to the flowable (RIGHT,left,CENTER)            y1 = y            x2 = x1 + self._wIDth            y2 = y1 + self._height            canvas.linkURL(url=self.hyperlink,rect=(x1,y1,x2,y2),thickness=0,relative=1)        super(HyperlinkedImage,self).drawOn(canvas,_sW)
总结

以上是内存溢出为你收集整理的python – ReportLab图片链接全部内容,希望文章能够帮你解决python – ReportLab图片链接所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1205271.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存