开发者

Referencing further pages with ReportLab

开发者 https://www.devze.com 2023-01-09 15:55 出处:网络
I\'m using ReportLab to create long questionnaires and I need to create text like 开发者_如何学运维If you do not have allergies, proceed to page 168

I'm using ReportLab to create long questionnaires and I need to create text like

开发者_如何学运维If you do not have allergies, proceed to page 168

Does ReportLab present some feature that can help me with this referencing task?

I understand that this problem probably needs a two-pass algorithm. In the first pass, the pages' numbers are found. The second pass completes the text, adjusting the references to the proper pages. Is something there in ReportLab API that could help in this context?


Its two years since the original question, but I will venture an answer for the sake of others that may land on this question from a search engine:

Reportlab supports internal links. The relevant section of the report lab user guide [ PDF only, available here ] reads...

PDF supports internal hyperlinks. There is a very wide range of link types, destination types and events which can be triggered by a click. At the moment we just support the basic ability to jump from one part of a document to another, and to control the zoom level of the window after the jump. The bookmarkPage method defines a destination that is the endpoint of a jump... [ section 4.2 ]


here is how did i make it work:

1, must register the destination like this (name is the key):

   st = ParagraphStyle('a style', alignment=TA_CENTER)
   from hashlib import sha1
   destination = sha1("Vintage".encode('utf-8')).hexdigest()
   b = Paragraph("My Page"+'<a name="%s"/>' % destination, st)
   b._bookmarkName = destination

   =====

2, later do this for the link on the paragraph you are going to do click (key point here is the harsh sign # in front ):

 contents = Paragraph(text="This <a href=#{} color=blue> Vintage </a>".format(destination), style=st)

on this paragraph you click Vintage you then go on to the destination page on your desire

0

精彩评论

暂无评论...
验证码 换一张
取 消