简体   繁体   中英

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. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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