Hyperlinks in a PowerPoint file not only can be linked to external URLs, but also to the specific slide within the document. This article will show you how to create a hyperlink that links to a specified slide using Spire.Presentation.
Step 1: Create a PowerPoint file and append a slide to it.
Presentation presentation = new Presentation(); presentation.Slides.Append();
Step 2: Add a shape to the second slide.
IAutoShape shape = presentation.Slides[1].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(10, 50, 200, 50)); shape.TextFrame.Text = "Jump to the first slide";
Step 3: Create a hyperlink based on the shape and the text on it, linking to the first slide .
ClickHyperlink hyperlink = new ClickHyperlink(presentation.Slides[0]); shape.Click = hyperlink; shape.TextFrame.TextRange.ClickAction = hyperlink;
Step 4: Save the file.
presentation.SaveToFile("hyperlink.pptx", FileFormat.Pptx2010);
Output:
Full Code:
[C#]
using Spire.Presentation; using Spire.Presentation.Drawing; using System.Drawing; namespace Link_to_a_Specific_Slide { class Program { static void Main(string[] args) { Presentation presentation = new Presentation(); presentation.Slides.Append(); IAutoShape shape = presentation.Slides[1].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(10, 50, 200, 50)); shape.Fill.FillType = FillFormatType.None; shape.Line.FillType = FillFormatType.None; shape.TextFrame.Text = "Jump to the first slide"; ClickHyperlink hyperlink = new ClickHyperlink(presentation.Slides[0]); shape.Click = hyperlink; shape.TextFrame.TextRange.ClickAction = hyperlink; presentation.SaveToFile("output.pptx", FileFormat.Pptx2010); } } }
[VB.NET]
Imports Spire.Presentation Imports Spire.Presentation.Drawing Imports System.Drawing Namespace Link_to_a_Specific_Slide Class Program Private Shared Sub Main(args As String()) Dim presentation As New Presentation() presentation.Slides.Append() Dim shape As IAutoShape = presentation.Slides(1).Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(10, 50, 200, 50)) shape.Fill.FillType = FillFormatType.None shape.Line.FillType = FillFormatType.None shape.TextFrame.Text = "Jump to the first slide" Dim hyperlink As New ClickHyperlink(presentation.Slides(0)) shape.Click = hyperlink shape.TextFrame.TextRange.ClickAction = hyperlink presentation.SaveToFile("output.pptx", FileFormat.Pptx2010) End Sub End Class End Namespace