[reportlab-users] how to call bookmarks from external links

Robin Becker robin at reportlab.com
Fri Jan 22 05:19:37 EST 2021


On 21/01/2021 12:09, Tobias Greitzke wrote:
> Hi,
> 
.......................
> 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?
> 

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


More information about the reportlab-users mailing list