I'm generating a pdf as part of an online documentation. Users should be
able to click on a link on the webpage that refers to a specific
endpoint in the generated pdf. Both, the webpage and the pdf are
generated from data, so I don't know on which page the
flowables/bookmarks are located within the pdf.
So far I created bookmarks for each endpoint:
title = flowable.text
key = str('s%s' %flowable.text) # here I use the database Id of the
object I want to link to
canvas.bookmarkPage(key)
canvas.addOutlineEntry(title, key, 0, 0)
canvas.showOutline()
In the Outline I get all the bookmarks and I can see links like:
https://www.mysite.com/report.pdf?projectId=41#[{"num":7,"gen":0},{"name":"Fit"}]
"num":7 seems to be the number of the last flowable on the page, but as
I don't know on which page the flowables will end up when I generate the
pdf, I can't generate links according to these bookmarks.
Is there a way to generate bookmarks that I can define by my data while
generating the pdf, so I can also use them in a generated link on the
webpage?
Thanks for your help,
Tobias
_______________________________________________
reportlab-users mailing list
reportl...@lists2.reportlab.com
https://pairlist2.pair.net/mailman/listinfo/reportlab-users
Hi Tobias,
it's not exactly clear from your question what exactly is the web page link and what your links actually look like.
I not really sure what 'https://www.mysite.com/report.pdf?projectId=41#[{"num":7,"gen":0},{"name":"Fit"}]' actually
refers to. Certainly the DocTemplate class does not count flowables generally.
First off the pdf internal bookmarks you show above are presumably referred to by their key value. I don't know exactly
how you are exporting the links for use in a web page. If you say that your web page / browser combo requires a specific
page number then you need to export that rather than the link. If in fact you are using some database numbers to define
the link then obviously you may need to obtain the page numbers if they are actually required by the web links. That
would make the information flow quite hard, but a first pass could generate the document and a mapping from the db links
to the page numbers.
Since you have access to the canvas in the snippet I assume you can just ask it for the current page number eg
my_list_of_page_numbers = {}
......
canvas.bookmarkPage(key)
my_list_of_page_numbers[key] = canvas._pageNumber
If you are in fact asking about something else then please explain and I'll try and answer
>
> Thanks for your help,
> Tobias
............
--
Robin Becker