简体   繁体   English

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

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

This is what the platypus documentation states:这是鸭嘴兽文档所述:

The link tag can be used as a reference, but not as an anchor.链接标签可以用作参考,但不能用作锚点。 The a and link hyperlink tags have additional attributes fontName, fontSize, color & backColor attributes. 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); The hyperlink reference can have a scheme of http:(external webpage), pdf:(different pdf document) or document:(same pdf document); a missing scheme is treated as document as is the case when the reference starts with # (in which case the anchor should omit it).缺少的方案被视为文档,就像引用以 # 开头的情况一样(在这种情况下,锚应该省略它)。 Any other scheme is treated as some kind of URI.任何其他方案都被视为某种 URI。

I want to create a clickable link that takes you to another page in the same pdf but im not sure how to create the "anchor", if anyone understands please can you help!我想创建一个可点击的链接,将您带到同一 pdf 中的另一个页面,但我不确定如何创建“锚”,如果有人理解,请您帮忙! (I am obviously not using a canvas) Thanks (我显然没有使用画布)谢谢

Solution: Just copy and paste code to test.解决方案:只需复制并粘贴代码进行测试。

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