Local Hyperlinks, Documentation demo
I am trying to create a hyperlink to another slide in the same presentation.
From the documentation on hyperlinks, I understand I need to create a run like this:
from pptx import Presentation
filepath = 'test.pptx'
pres = Presentation(filepath)
slide = pres.slides[0]
paragraph = slide.shapes[0].text_frame.paragraphs[0]
run = paragraph.add_run()
run.text = "hello world"
run.hyperlink.address = 'https://github.com/scanny/python-pptx'
The documentation is a bit hard for me to understand regarding how to create a hyperlink to a target within the PowerPoint file itself. The quote from the documentation is:
Hyperlinks in PowerPoint can have four types of targets: .... another part in the same presentation. This uses an internal relationship (in the .rels item) to the target part.
Can you describe in detail how to create a target using the .rels item and how to hyperlink to that target? Thanks!
I found that you can hyperlink to a slide by formatting the "URL" like this:
run.hyperlink.address = "#Slide 3"
That did the trick.
There's a new feature in the last month or so enabling this more directly:
shape.click_action.target_slide = prs.slides[3]
http://python-pptx.readthedocs.io/en/latest/api/shapes.html#pptx.shapes.base.BaseShape.click_action
How is this done with run using this new method?
The .click_action property is currently only on a shape, not yet a Run object. So it's still the old method there if you're constrained to making a link from text (like a traditional hyperlink).
hey scanny i want to create a text including hyperlink word in it like source:ancbhfd "jkl"asdf as u see jkl is my hyperlink text so how can i make it?
I found that you can hyperlink to a slide by formatting the "URL" like this:
run.hyperlink.address = "#Slide 3"That did the trick.
Is "#Slide 3" in this example the name property of a slide, or the slide ID? And is the # symbol part of that name/ID, or the indicator that this is an internal link?
I found that you can hyperlink to a slide by formatting the "URL" like this:
run.hyperlink.address = "#Slide 3"That did the trick.
Is "#Slide 3" in this example the name property of a slide, or the slide ID? And is the # symbol part of that name/ID, or the indicator that this is an internal link?
I have the same question. @scanny or @doakey3 ?
I played around with the link in powerpoint itself, it generates a link of this nature:
https://docs.google.com/presentation/d/1FWKElbximUY3QB5a-APbRl6Uo/edit#slide=id.p2
and if we will use #slide=id.p2 it works!
For myself, I have found the following to be a temporary solution:
run.hyperlink.address = f'#slide=id.p{slide_id}'
Warning: id of your slides may have different format, not suitable for everyone