繁体   English   中英

如何使用鸭嘴兽和 ReportLab Pdf python 创建链接和锚点

[英]How to create a link and anchor using platypus and ReportLab Pdf python

这是鸭嘴兽文档所述:

链接标签可以用作参考,但不能用作锚点。 a 和 link 超链接标签具有额外的属性 fontName、fontSize、color 和 backColor 属性。 The hyperlink reference can have a scheme of http:(external webpage), pdf:(different pdf document) or document:(same pdf document); 缺少的方案被视为文档,就像引用以 # 开头的情况一样(在这种情况下,锚应该省略它)。 任何其他方案都被视为某种 URI。

我想创建一个可点击的链接,将您带到同一 pdf 中的另一个页面,但我不确定如何创建“锚”,如果有人理解,请您帮忙! (我显然没有使用画布)谢谢

解决方案:只需复制并粘贴代码进行测试。

from reportlab.platypus import Paragraph, PageBreak, SimpleDocTemplate
from reportlab.lib.styles import getSampleStyleSheet

pdf = SimpleDocTemplate('PDFname.pdf')
story = []
styles = getSampleStyleSheet()
story.append(Paragraph('This <a href="#MYANCHOR" color="blue">is a link to</a>', style=styles["Normal"])) # Linking the anchor
story.append(PageBreak())
story.append(Paragraph('<a name="MYANCHOR"/><font color="green">here</font>', style=styles["Normal"])) # Creating anchor
pdf.build(story)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM